【问题标题】:style is not applied at runtime but being applied at design time in wpf样式不在运行时应用,而是在 wpf 的设计时应用
【发布时间】:2013-05-22 10:04:40
【问题描述】:

我在位于 WPFResources.dll 中的资源字典中有一个简单样式,我在另一个项目中访问此样式,我可以看到在设计时正在应用该样式,但是当我运行应用程序时,我我遇到了"Cannot find resource named 'IndentCheckBoxStyle'. Resource names are case sensitive" 的异常。如果我使用 StaticResource,那么我可以看到这个异常,如果我使用 DynamicResource,那么我看不到任何异常,但 UI 上什么也看不到。

关于这个问题的更多信息:

我在我的项目中引用了 WPFResources.dll 并将其合并到 App.XAML 中,如下所示:

<Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/WPFResources;component/Theme.xaml" />
        </ResourceDictionary.MergedDictionaries>        
    </ResourceDictionary>
    </Application.Resources>

在 Theme.xaml 中我已经合并了 cheboxstyle 的资源字典。

有人对此有任何想法吗??

提前致谢。

【问题讨论】:

  • 你把相关代码贴出来怎么样?
  • WPFResources.dll 在应用程序 bin 路径中可用吗?
  • 是的,它在 Bind 文件夹中,我已在 App.XAML 中添加
  • 我的问题已经解决了。
  • 如果你解决了你的问题,请发布答案,我也有同样的问题,现在我不知道你是如何解决的。

标签: wpf resourcedictionary


【解决方案1】:

我遇到了这个问题,发现样式正在使用 Pack URI 语法应用于整个应用程序,

例如在 App.xaml 中

<Application x:Class="Framework.Presentation.Preview.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Abt.Framework.Presentation;component/Themes/AbtDark.xaml"/>
            </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
    </Application.Resources>
</Application>

但是,隐式样式并未应用于应用程序的顶级窗口(尽管 MyTheme.xaml 包含未命名的窗口样式)

为了解决这个问题,我只是为 Window 使用了一个命名样式(不是隐式样式)。其余的都正确应用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多