Search code examples
c#wpfxamldevexpress-wpf

WPF Style in external file crashes


I have a C# usercontrol with a DevExpress GridControl in it. When I use a style for the GridColumns in the local xaml file like below, everything works

<UserControl.Resources>
    <ResourceDictionary>
        <Style x:Key="K2M_GridColumn" TargetType="{x:Type dxg:GridColumn}">
            <Setter Property="AllowBestFit" Value="True" />
            <Setter Property="AllowColumnFiltering" Value="False" />
            <Setter Property="AllowEditing" Value="False" />
            <Setter Property="AllowSorting" Value="False" />
        </Style>

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/RefImpl.Common.Client;component/Controls/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

If I move the above GridColumn style into the Styles.xaml the VS Designer breaks and shows this.

Exception: An error occurred while finding the resource dictionary "/RefImpl.Common.Client;component/Controls/Styles.xaml".
Error   XDG0012 The member "AllowBestFit" is not recognized or is not accessible.
Error   XDG0012 The member "AllowColumnFiltering" is not recognized or is not accessible.
...

If I remove the GridColumn style from Styles.xaml everything compiles and works, except that I don't have the style ofc. So as long as I don't add the GridColumn style to the Styles.xaml file everything works.

I have defined this at the top in both the local xaml file and the Styles.xaml file

xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"

Any suggestions on what's causing the error?


Solution

  • I found the issue! It was a mismatch of versions of DevExpress. In the project with the xaml control I was using a older version of DevExpress and in the project with the Styles.xaml I was using a newer version of DevExpress.

    For some unknown reason that causes a big runtime crash and Designer issues. No error messages though.