我只是以编程方式从 devexpress 和所有单元格创建一个 GridControl 并以这种方式绑定它的 ItemsSource
var gridControlAzmayesh = new GridControl
{
View = tv,
ItemsSource = new CollectionViewSource
{
Source = list// include some column : id,name,last name
}.View
};
现在我想将一个按钮放在一个列中并通过 id 绑定它,当单击按钮时打开一个用户控件与相应的行 id 但它不起作用我的代码是:
var template = new DataTemplate();
var buttonFactory = new FrameworkElementFactory(typeof(Button)) ;
buttonFactory.SetValue(Button.ContentProperty,"....");
buttonFactory.SetBinding(Button.TagProperty, //add id to tag
new Binding()
{
XPath = "Id", // not binding work
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
buttonFactory.AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler((sender, args) =>
{
var aa = ((Button)sender).Tag; // read tag
var uc = new UcEditAzmayeshSabeghe((int) aa); // initialize a user control to open whit row id
UcPopupSabeghe.Child = uc;
UcPopupSabeghe.Placement = PlacementMode.Mouse;
UcPopupSabeghe.StaysOpen = false;
UcPopupSabeghe.AllowsTransparency = true;
UcPopupSabeghe.IsOpen = true;
}));
template.VisualTree = buttonFactory;
gridControlAzmayesh.Columns.Add(new GridColumn
{
FieldName = "Id",
Header = "...",
CellTemplate = template,
Width = new GridColumnWidth(40, GridColumnUnitType.Pixel)
});
gridControlAzmayesh.View = new TableView() { UseLightweightTemplates = UseLightweightTemplates.Row };
我无法在 XAML 中创建我的 gridControl,因为我在许多不同的选项卡中创建了许多具有不同列的 gridControl:我知道,你为什么这么害怕 XAML,但是 XAML 不够灵活:太多了!
正是“id”没有绑定到按钮我想获取每一行 id 并将其绑定到按钮标签属性。