Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
704
Bind "BackgroundActive" to ViewModel property
posted

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>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Parents
No Data
Reply
  • 9694
    posted

    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!

Children