【发布时间】:2019-12-13 10:20:41
【问题描述】:
我在 WPF 中使用 MaterialDesign for XAML 包。当我运行我的应用程序时,所有样式和控件都按预期呈现。然而,在 XAML 设计器中,我遇到了许多错误,例如“无法解析资源‘MaterialDesignFlatButton’”。抛出该错误的行示例:
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" ...
我的app.xaml内容如下:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.LightBlue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我尝试了The resource "x" could not be resolved. 上提出的最佳解决方案,但这会导致项目无法运行(我相信在尝试使用建议的“绝对包 URI”时我没有使用正确的路径)。所以我现在有两个问题:
- 鉴于我在 App.xaml 中定义资源的方式(根据开发人员指南:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/Getting-Started),XAML 设计器中的资源无法解析是否有原因?
- 如何找到“绝对包 URI”以用作我的资源字典的来源?
【问题讨论】:
-
你有没有设法解决这个问题?
标签: c# wpf xaml material-design-in-xaml