i just create a GridControl from devexpress and all cell programmatically and bind its ItemsSource in this way
var gridControlAzmayesh = new GridControl
{
View = tv,
ItemsSource = new CollectionViewSource
{
Source = list// include some column : id,name,last name
}.View
};
now i want to put a button in a column and bind it by id and when click in button open a user control whit corresponding row id but its not working my code is:
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 };
i cant create my gridControl in XAML because i create many gridControl with different Columns in many different Tab :Why are you so afraid of XAML i know, but XAML doesn't flexible enough :Sooo much!
exactly "id" not binding into a button i want to get every row id and bind it to a button tag properties.