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
339
Access Resources Programmatically?
posted

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 null
Style headerStyle = x.Resources["headerStyle"] as Style;

 

Thanks,

Jamie

Parents
  • 6867
    Verified Answer
    posted

     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.

Reply Children
No Data