c# - 名称空间中不存在名称“XamlDisplay”
问题描述
我正在尝试在 xaml Toolkit 中实现 Material Design 并收到此错误
The name "XamlDisplay" does not exist in the namespace "clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
我刚刚从官方文档Xaml 代码中复制并粘贴了这段代码
我已经尝试过此处提供的解决方案StackOverflow 上的其他问题,例如将调试更改为发布模式、清理 shadowCache 和 DLL 文件权限。
但这些都只是技巧,不是可靠的答案,它们对我不起作用。怎么了?
我的 Xaml 代码
<Window x:Class="MaterialTestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MaterialTestApp"
mc:Ignorable="d"
xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
<Grid>
<StackPanel Margin="8 8 0 0">
<TextBlock>Raised controls have default shadows set, but the shadows can be overriden.</TextBlock>
<StackPanel Orientation="Horizontal" Margin="0 32 0 0">
<smtx:XamlDisplay Key="shadow_1">
<Button Style="{DynamicResource MaterialDesignRaisedButton}"
>DEPTH 1</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_2" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignRaisedButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth2"
>DEPTH 2</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_3" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignRaisedButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth3"
>DEPTH 3</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_4" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignRaisedButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth4"
>DEPTH 4</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_5" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignRaisedButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth5"
>DEPTH 5</Button>
</smtx:XamlDisplay>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 32 0 0">
<smtx:XamlDisplay Key="shadow_6">
<Button Style="{DynamicResource MaterialDesignFloatingActionMiniButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth1"
>1</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_7" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignFloatingActionMiniButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth2"
>2</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_8" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignFloatingActionMiniButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth3"
>3</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_9" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignFloatingActionMiniButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth4"
>4</Button>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_10" Margin="16 0 0 0">
<Button Style="{DynamicResource MaterialDesignFloatingActionMiniButton}"
materialDesign:ShadowAssist.ShadowDepth="Depth5"
>5</Button>
</smtx:XamlDisplay>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 32 0 0">
<smtx:XamlDisplay Key="shadow_11">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Padding="32">DEPTH 1</materialDesign:Card>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_12" Margin="16 0 0 0">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth2" Padding="32">DEPTH 2</materialDesign:Card>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_13" Margin="16 0 0 0">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth3" Padding="32">DEPTH 3</materialDesign:Card>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_14" Margin="16 0 0 0">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth4" Padding="32">DEPTH 4</materialDesign:Card>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_15" Margin="16 0 0 0">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth5" Padding="32">DEPTH 5</materialDesign:Card>
</smtx:XamlDisplay>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0 32 0 0">
<smtx:XamlDisplay Key="shadow_16">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth3" materialDesign:ShadowAssist.ShadowEdges="Bottom,Right" Padding="32">CUSTOM CLIP</materialDesign:Card>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_17" Margin="16 0 0 0">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth3" materialDesign:ShadowAssist.ShadowEdges="Top" Padding="32">CUSTOM CLIP</materialDesign:Card>
</smtx:XamlDisplay>
<smtx:XamlDisplay Key="shadow_18" Margin="16 0 0 0">
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth3" materialDesign:ShadowAssist.ShadowEdges="Bottom,Left" Padding="32">CUSTOM CLIP</materialDesign:Card>
</smtx:XamlDisplay>
</StackPanel>
</StackPanel>
</Grid>
应用程序.Xaml
<Application x:Class="Test_App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Test_App"
StartupUri="MainWindow.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.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
解决方案
我是 ShowMeTheXaml 的作者。该项目的目的是为 MaterialDesignInXAML (MDIX) 中的演示应用程序提供显示 MDIX 控件和样式的相应 XAML 的功能。除非您希望在您的应用程序中使用相同的功能(不太可能),否则您可以从项目中删除 ShowMeTheXaml。至于您的 xaml,您可以简单地删除<smtx:XamlDisplay>
标签并保留内容。
推荐阅读
- json - 调试时,尝试在 .Net Core 中调用 JsonResult 时出现错误代码 404
- image - 使用 python 和 PIL 在图像上写德语文本的问题
- mysql - 如何按 id 范围自动递增?
- c# - 当我有可用的公钥、私钥和 ca 文件时,如何从 HTTPS 自签名网页中检索 (GET) 数据?
- c++ - C++/Qt 5 GStreamer 继续循环
- angular - 如何在 Angular 中添加事件监听器?
- c++ - 派生类中的方法重写使基类中的重载方法无法使用
- android - 我想在后台通话结束后从通话记录中将数据存储在本地
- php - 如何有效地计算数组中的值块
- blockchain - 迁移耗尽气体