private void DataGridScanChannel_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) 
        {            
            var styleCell = new Style(typeof(DataGridCell))
            {
                Setters = { new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Right) }
            };
            e.Column.Header = MemoryChannelHeader[e.PropertyName];
            e.Column.CellStyle = styleCell;
            DataGridTextColumn txtcol = e.Column as DataGridTextColumn;

            switch (e.PropertyName)
            {
                case "Prog_No":
                    var buttonTemplate = new FrameworkElementFactory(typeof(System.Windows.Controls.Button));
                    var text = new FrameworkElementFactory(typeof(TextBlock));
                    text.SetValue(TextBlock.TextProperty, "Start");
                    buttonTemplate.AppendChild(text);
                    //buttonTemplate.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent, new RoutedEventHandler((o, e) => System.Windows.MessageBox.Show("hi")));
                    buttonTemplate.AddHandler(System.Windows.Controls.Button.ClickEvent, new RoutedEventHandler(Btn_Click));
                    DataGridScanChannel.Columns.Add(new DataGridTemplateColumn()
                    {
                        Header = "Scan",
                        DisplayIndex = 0,
                        CellTemplate = new DataTemplate() { VisualTree = buttonTemplate }
                    });
                    break;
                case "Prog_Mode":
                    e.Cancel = true;
                    break;
                case "Prog_Freq_Lower":
                    txtcol.Binding = new System.Windows.Data.Binding(e.PropertyName) { StringFormat = "{0:N0}" };
                    txtcol.Width = 100;
                    //e.Column.DisplayIndex = 1;
                    break;
                case "Prog_Freq_Upper":
                    txtcol.Binding = new System.Windows.Data.Binding(e.PropertyName) { StringFormat = "{0:N0}" };
                    txtcol.Width = 100;
                    //e.Column.DisplayIndex = 2;
                    break;
                default:
                    break;
            }
        }
カテゴリー: Visual Studio

0件のコメント

コメントを残す

アバタープレースホルダー