Hello,
Should it be possible to access the resources of a XamDataGrid programatically?
I'm trying to reference a style but my resources collection contains zero items. If I move the style inside my grid resources it appears as expected. Unfortunately I need the style to live within the XamDataGrid resources. E.g.
XAML<igDP:XamDataGrid Name="x" Theme="LunaNormal" ThemeChanged="x_ThemeChanged"> <igDP:XamDataGrid.Resources> <Style x:Key="headerStyle" TargetType="{x:Type igDP:LabelPresenter}" BasedOn="{x:Static igThemes:DataPresenterLunaNormal.LabelPresenter}"> <Setter Property="Foreground" Value="Red" /> </Style> </igDP:XamDataGrid.Resources> </igDP:XamDataGrid>
C#// This returns nullStyle headerStyle = x.Resources["headerStyle"] as Style;
Thanks,
Jamie
You should use WPF's built-in FindResource() method, or TryFindResource(). Using the indexer on Resources (ex. x.Resources[foo]) will not perform a resource lookup. This behavior is part of WPF, not specific to XamDataGrid.
Thanks Josh.