包含MaterialDesignInXaml

时间:2019-05-08 10:42:03

标签: c# wpf textbox material-design-in-xaml

我正在构建一个库(用于Revit的插件)。我有一个Window,其中已经成功包含了Material design。

当我尝试向此TextBox添加Window控件时,出现以下错误

  

System.Windows.Markup.XamlParseException:'在'System.Windows.Markup.StaticResourceHolder'上提供值引发了异常。'
  内部异常:NotImplementedException:方法或操作未实现。

由于我正在构建库,所以没有App.xaml文件,因此我创建了具有以下内容的资源字典:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <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.DeepPurple.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

我使用

将其包含到我的Window
<Window.Resources>
    <ResourceDictionary Source="/MyAsembly;component/MaterialDesign.xaml" />
</Window.Resources>

正如我所说,使用简单的TextBox会抛出一个异常,没有样式,没有任何东西

<TextBox />

到目前为止,在窗口/页面中包含“材质设计”之后,我到目前为止使用的所有其他WPF控件都可以正常工作。

在同一应用中,我已经有Window的另一个TextBox。如果尝试将MaterialDesign包含到该Window中,则会出现相同的错误;如果没有MaterialDesing,TextBox将正常工作。如果我包含MaterialDesing并注释掉TextBox,则代码可以正常工作。

我们非常感谢您的帮助。

编辑:可以here找到演示该问题的演示应用。

2 个答案:

答案 0 :(得分:0)

您还必须提供XAML namespaceResourceDictionary声明,如下所示。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <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.DeepPurple.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

答案 1 :(得分:-1)

将此行放入您的主窗口标签  xmlns:materialDesign =“ http://materialdesigninxaml.net/winfx/xaml/themes”