【问题标题】:WPF Style in external file crashes外部文件崩溃中的 WPF 样式
【发布时间】:2021-05-31 18:01:11
【问题描述】:

我有一个带有 DevExpress GridControl 的 C# 用户控件。 当我在本地 xaml 文件中为 GridColumns 使用如下样式时,一切正常

<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>

如果我将上述 GridColumn 样式移动到 Styles.xaml 中,VS 设计器会中断并显示此内容。

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.
...

如果我从 Styles.xaml 中删除 GridColumn 样式,一切都会编译并正常工作,除了我没有样式 ofc。 因此,只要我不将 GridColumn 样式添加到 Styles.xaml 文件中,一切正常。

我在本地 xaml 文件和 Styles.xaml 文件的顶部都定义了这个

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

对导致错误的原因有什么建议吗?

【问题讨论】:

  • 尝试将项目的目标框架切换到更高版本。 .Net Framework 版本之间可能存在差异。
  • 这只是设计者的问题,即当您运行应用程序时它是否有效?
  • 这不是设计师独有的问题。创建具有该样式的视图时,应用程序会严重崩溃。
  • @Rekshino 这是我不同项目中 DevExpress 版本之间的不匹配,您的评论为我指明了正确的方向。谢谢!

标签: c# wpf xaml devexpress-wpf


【解决方案1】:

我发现了问题!这是 DevExpress 版本的不匹配。 在带有 xaml 控件的项目中,我使用的是旧版本的 DevExpress,而在带有 Styles.xaml 的项目中,我使用的是较新版本的 DevExpress。

由于某些未知原因导致运行时大崩溃和设计器问题。但没有错误消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    相关资源
    最近更新 更多