0

我有 WPF 数据网格用户控件,我必须在 Winforms 中托管它。WPF Datagrid 控件嵌入在用户控件中。我有一个 winforms 应用程序,其中包含元素主机控件。元素宿主的子元素是 WPF 用户控件(具有数据网格的用户控件)。在 wpf 数据网格上,我对每一行都有一个复选框(在加载一行时动态创建)。

当 wpf 用户控件在 winforms 中加载时,(在元素主机上)我可以获取行,但不能获取复选框。复选框可见性可见,我可以在行中看到一些占位符。

有什么我错过的吗?我是否需要在 wpf datagrid 上以不同方式声明复选框,以便它在 winforms 上也可见?

这是复选框创建的代码

DataGridTemplateColumn col1 = new DataGridTemplateColumn();
col1.Header = "Select Columns";
col1.Width = 30;
FrameworkElementFactory factory1 = new FrameworkElementFactory(typeof(CheckBox));
Binding b1 = new Binding("IsSelected");
b1.Mode = BindingMode.TwoWay;
factory1.SetValue(CheckBox.IsCheckedProperty, b1);
factory1.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(chkSelect_Checked));
factory1.AddHandler(CheckBox.UncheckedEvent, new RoutedEventHandler(chkSelect_UnChecked));
DataTemplate cellTemplate1 = new DataTemplate();
cellTemplate1.VisualTree = factory1;
col1.CellTemplate = cellTemplate1;
col1.CellStyle = new Style();
col1.Visibility = Visibility.Visible;
dgGrid.Columns.Add(col1);
4

0 回答 0