Hello,
I have the following XAML and the BackgroundActive property in my ViewModel gets read, but doesn't seem to get set in the datagrid. If I hardcode a brush color to the BackgroundActive value, it displays as it should. Any help much appreciated.
<igDP:XamDataGrid Name="DocumentsGrid" DataSource="{Binding Documents}" ActiveDataItem="{Binding SelectedRow}" RecordLoadMode="{Binding GridRecordLoadMode, Mode=OneTime}" RecordContainerGenerationMode="{Binding ContainerGenerationMode, Mode=OneTime}">
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Setter Property="BackgroundActive" Value="{Binding DataContext.ActiveGridRowColor, ElementName=DocumentsGrid, Mode=OneWay}"/>
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AllowEdit="False" />
</igDP:XamDataGrid.FieldSettings>
</igDP:XamDataGrid>
One solution is to use a DataTrigger in a CellValuePresenterStyle.
Try the following:
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding Record.IsActive, RelativeSource={RelativeSource Self}}" Value="True"> <Setter Property="BackgroundActive" Value="{Binding Path=ActiveGridRowColor, Source={StaticResource myDataSource}}" /> </DataTrigger> </Style.Triggers></Style>
This is declared as a global style. You can give this style a Key and assign it to all Fields by assigning the resource to the FieldLayout.FieldSettings.CellValuePresenterStyle or to individual Fields as well using the FieldLayouts.Field.FieldSettings.CellValuePresenterStyle.
I'm not sure how your data is set up. Is it safe to assume you have a property in your main data source called ActiveGridRowColor. And there is also a property called Documents. Since your XAML snippet doesn't include where the data is declared, I've added a Source declaration which assumes a data source declared in a resource with key myDataSource. If this isn't enough to get you going, send more info about the data so I might make sure the binding expression works.
Thank you!
Thanks for your reply Curtis, I tried using your implementation and it doesn't seem to work.
I tried doing it globally with a key. I removed the Source binding for myDataSource because I'm not sure what that is exactly (sorry for my noobishness, I usually just bind a ViewModel to a user control and that's my data source) and I assigned the style you provided to the FieldSettings CellValuePresenterStyle.
My DataContext (MyViewModel) for the user control does indeed have an ActiveGridRowColor and a Documents. In the code behind for my control, I just set the datacontext in the constructor: this.DataContext = new MyViewModel()
Documents is the data source for the grid and I'd like ActiveGridRowColor to be able to set the style's active background color for the selected row.
My previous implementation read the ActiveGridRowColor property, but the brush never got set...