c# - 仅错误消息设计时:“无法找到资源 'styles/buttonstyles.xaml'”
问题描述
在以下场景中出现一条神秘消息:无法找到资源“样式/按钮样式.xaml”
此消息仅在设计模式下出现,无法摆脱。如果我重建解决方案,错误消息会消失,直到我打开 ApplicationWindow.xaml。
环境如下:
MainWindow.xaml:
...
<Grid Grid.Row="1">
<controls:CustomToolbar Style="{StaticResource ToolBarStyle}"/>
</Grid>
...
问题指向控件:CustomToolbar部分。
自定义工具栏.xaml:
<UserControl x:Class="Frontend.Views.Controls.CustomToolbar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Frontend.Views"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Styles/ButtonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/Views/GlobalStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource ToolbarButton}" Command="{Binding NewProjectCommand}" ToolTip="New project">
<Image Source="{StaticResource NewProject}" Stretch="None" />
</Button>
<StackPanel Orientation="Horizontal">
<Separator Height="20" Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
</StackPanel>
</StackPanel>
</UserControl>
如果我更改合并字典的顺序,错误消息会切换到第一个。
我试过的:
- google 和 stackoverflow 的每个链接
- 清理解决方案,包括删除 bin、obj、.vs 文件夹,然后重新构建。
- 重新启动 Visual Studio,重新启动 PC
- 使用完全限定的 URI -> 不起作用,这些字典在当前程序集中。
- 每个 ResourceDictionary 的属性都设置为 BuildAction:Page 和 MSBuild:Compile
如果我不使用任何 ResourceDictionary,则不会出现错误消息。
编辑1:
这是项目结构: 这里
ResourceDict 用法: 这里
谢谢,诺伯特
解决方案
你还没有引入命名空间
<controls:CustomToolbar Style="{StaticResource ToolBarStyle}"/>
是程序。
将以下行添加到 Window 标记
xmlns:controls="clr-namespace:Your name space.Views.Controls"
看看在哪里CustomToolbar
,根据上面的代码输入
推荐阅读
- node-opcua - 一个订阅中的多个变量
- cmd - 我无法对程序文件使用 where 命令
- r - 修改一行数据以获得漂亮的输出(摘要),重塑 - 将行拆分为新的多列
- java - 缓冲阅读器抛出异常
- testing - 赛普拉斯,如何检查属性是否存在
- python - Fizzbuzz Challenge in Twilio quest
- html - 如何在 WordPress 中让这些行彼此相邻?
- python - tkinter - 为什么会有像 bbox 这样的东西?
- python - Tensorflow:PartialTensorShape:合并期间不兼容的等级:2 vs. 1
- php - 调用未定义的函数 apcu_add()