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;
}
}
How to add button to WPF DataGrid column in code programmatically
<summary> .NET Awesome Links BPMN BPMS c# Chocolatey Cluster Server Command Window Community Edition Dance DataGrid Diff DiffFiles Dig Examples Font Family FORTRAN go Google Admin Toolbox Install LibreCAD MinGW OpenForm OpenRadioss Opensource ParaView PhotoScapeX pip QCAD tags Tips Violin WP Control WPF xps15 zbuild 一括変更 罫線 色

コメントを残す
コメントを投稿するにはログインしてください。