I want to create a xamDataGrid for a ViewModel which has a list of "parameter"s, this kind of "parameter" is read from the database, so I have no idea how many parameters there will be. In that case, I cant directly create property for them in the ViewModel. My ViewModel is like this:
public class MyViewModel
{
public string Name{get;set;}
public List<Parameter> Parameters{get;set;}
}
public class Parameter
public string ParameterName{get;set;}
public string Value{get;set;}
I want these parameters to be columns as same as the "Name" of "MyViewModel".
Is this approach ok without violating the MVVm pattern? Thanks
That really helped me, thank you so much.
Hello,
I have been looking into your code snippets and I can suggest you just slightly modify the BindingPath property of the unbound columns as follows:
BindingPath = new PropertyPath("Parameters[" + i + "]"),
For additional reference please check the attached sample which I modified in order to suit your scenario.
If you have any additional questions or concerns with this matter please feel free to ask.
Thanks for your reply, I have resolved this problem. Unfortunately, I found another problem about this solution, the data structure is like this(AvailableValues in parameter is different from the others):
public List Parameters{get;set;}
public string ParameterValue{get;set;}
public List AvailableValues{get;set;}
And I wanna the cell as a combobox, so I implemented a style for the CellValuePresenter:
<Style x:Key="ShowComboboxCellStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Border BorderThickness="0,0,1,0" BorderBrush="{TemplateBinding BorderBrush}">
<ComboBox SelectedItem="{Binding Path=Value.ParameterValue, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ItemsSource="{Binding Path=Value.LegalValues, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I set UnboundField's BindingPath to “Parameters[” + current index + “]” Now all the things can be displayed. But the Filter of the field become useless. Do you know how to fix it or have another idea to implement this requirement.
Thank you for your post. I have been looking into the functionality that you wish to achieve and in order to do that you should generate the Fields for the XamDataGrid in code and set the AutoGenerateFields property of the FieldLayoutSettings of the XamDataGrid to false, since by default, the XamDataGrid will display the Parameters collection as a second level of hierarchy, in a separate FieldLayout. In order to generate the fields you can handle the FieldLayoutInitialized event of the XamDataGrid and there, for each item of Parameters collection, you can create an UnboundField and set its BindingPath to “Parameters[” + current index + “].Value”, in order to display each parameter as a field, instead of hierarchy. I have created a sample application for you that demonstrates how you can implement this approach.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support