【发布时间】:2021-02-11 22:19:51
【问题描述】:
在以下场景中出现了一条神秘消息: 找不到资源'styles/buttonstyles.xaml'
此消息仅在设计模式下出现,不能被忽略。如果我重建解决方案,错误消息会消失,直到我打开 ApplicationWindow.xaml。
环境如下:
MainWindow.xaml:
...
<Grid Grid.Row="1">
<controls:CustomToolbar Style="{StaticResource ToolBarStyle}"/>
</Grid>
...
问题指向controls:CustomToolbar部分。
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,重启电脑
- 使用完全限定的 URI -> 不起作用,这些字典在当前程序集中。
- 每个 ResourceDictionary 的属性都设置为 BuildAction:Page 和 MSBuild:Compile
如果我不使用任何 ResourceDictionary,则不会出现错误消息。
EDIT1:
这是项目结构: HERE
ResourceDict 用法: HERE
谢谢, 诺伯特
【问题讨论】:
-
项目结构是什么,东西放在哪里,用在哪里?
标签: c# wpf xaml resourcedictionary