Reputation: 1171
I'm working on a WPF application and I need to set the FieldLayout Property of a XamDataGrid on the ViewModel. Once I achieve this I will be able to show the binded data on the XamDataGrid.
The tricky part is that I need to set the FieldLayout programmatically, hence I'm not allowed to do this:
<Grid>
<igWPF:XamDataGrid DataSource="{Binding Path=StaffMembers}"
FieldLayoutInitialized="xamDataGrid_FieldLayoutInitialized">
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings AutoGenerateFields="False"/>
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:XamDataGrid.FieldLayouts>
<igWPF:FieldLayout>
<igWPF:Field Name="Name"/>
<igWPF:Field Name="Department"/>
<igWPF:FieldLayout>
<igWPF:XamDataGrid.FieldLayouts>
<igWPF:XamDataGrid>
</Grid>
So my question is: Is it possible to set a FieldLayout property in the ViewModel? How?
Upvotes: 0
Views: 2744
Reputation: 3228
Why would you set the FieldLayout in the ViewModel? The FieldLayout is specific to the XamDataGrid and part of the View which your ViewModel shouldn't know about. This becomes important if you want to change the View to be a different grid at a later time or even just present a different view of the same data.
If you are simply looking to set what fields are available in the grid from within your view model, you should be able to expose a Property on the ViewModel that has this information and then in the View only add those fields to the XamDataGrid.
The simplest approach to this would be to add the necessary code to the code behind of the view to add the fields to the field layout. A more complex approach would be to use a Behavior or an attached property for the XamDataGrid that would allow you to bind the list of fields to show.
Upvotes: 3