Hi
I have to add dynamic columns to my XamDataGrid, the thing is that for each dynamic columns I have a custom style template with a custom user control inside, this user control is almost the same as a combo box, it has items and it has a selected item.
My problem is that the grid have to bind to one source and my:ScoreControl have to bind to another source dinamycally generated, and the SelectedItem property of my:ScoreControl have to bind with the same source of my grid has.
This is easy in WinForm but I having problem in WPF, I wondering if anyone can help me.
<Style x:Key="id6" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
ItemSelected="{Binding ???}"></my:ScoreControl>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
Maybe I'm not on the right way, and please tell me if I'm not clear.
Hello Erwin,
ItemSelected - if you want to bind it to whatever the XamDataGrid is bound to, you have to use something like this:
Binding Path=DataPresenter.DataSource, RelativeSource={RelativeSouce TemplatedParent}.
This should bind to the DataPresenter property of the CellValuePresenter, which represents the XamDataGrid.
Items - I am not sure to what you want to bind this one. Can you please give us more specific details so that I can give you a proper xaml binding expression?
Hi Alex,
Of course and thanks for answer.
Items is a collection that has a value and display member (the same as combobox), for each column I have a collection to bind to my custom user control. I could put the collection in every row of my DataTable and my problem is solved (a DataTable is the datasource of my grid) but I think is not right, I have hundreds of rows in my DataTable, in this case the most efficient way to do it is to create resources dynamically in code behind, and then in the grid bind my usercontrol to the respective resource.
My problem is to do all that in code behind. Because all that would be generated dynamically.