找不到资源字典

Cannot find resource dictionaries

所以下图说明了一切。 WPF 无法找到 xaml 个文件中的 一些 个。我试过将它们四处移动,但无济于事。他们都将构建操作设置为页面,将自定义工具设置为 MSBuild:Compile。不知道我在这里错过了什么。

编辑

根据要求,这里有两个示例 xaml 文件。其中一个有效,另一个无效。

GroupBox.xaml(工作一)

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Shared.xaml" />
</ResourceDictionary.MergedDictionaries>

<!-- SimpleStyles: GroupBox -->
<Style TargetType="GroupBox">
    <Setter Property="Control.Foreground" Value="#4C4C4C"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="GroupBox">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Border Grid.Row="0" 
                Background="{StaticResource LightBrush}"
                BorderBrush="{StaticResource NormalBorderBrush}"
                BorderThickness="1" 
                CornerRadius="2,2,0,0" >
          <ContentPresenter Margin="4"
                            HorizontalAlignment="Center"
                            ContentSource="Header" 
                            RecognizesAccessKey="True" />
        </Border>
        <Border Grid.Row="1" 
                Background="{StaticResource WindowBackgroundBrush}"
                BorderBrush="{StaticResource SolidBorderBrush}" 
                BorderThickness="1,0,1,1" 
                CornerRadius="0,0,2,2" >
          <ContentPresenter Margin="4" />
        </Border>
        </Grid>
        </ControlTemplate>
        </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Toolbox.xaml(无效)

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:s="clr-namespace:DiagramDesigner">
<Style TargetType="{x:Type s:Toolbox}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type s:Toolbox}">
      <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
              Padding="{TemplateBinding Control.Padding}"
              BorderBrush="{TemplateBinding Border.BorderBrush}"
              Background="{TemplateBinding Panel.Background}"
              SnapsToDevicePixels="True">
        <ScrollViewer VerticalScrollBarVisibility="Auto">
          <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </ScrollViewer>
      </Border>
    </ControlTemplate>
  </Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
  <Setter.Value>
    <ItemsPanelTemplate>
      <WrapPanel Margin="0,5,0,5"
                 ItemHeight="{Binding Path=ItemSize.Height, RelativeSource={RelativeSource AncestorType=s:Toolbox}}"
                 ItemWidth="{Binding Path=ItemSize.Width, RelativeSource={RelativeSource AncestorType=s:Toolbox}}"/>
    </ItemsPanelTemplate>
  </Setter.Value>
  </Setter>
  </Style>
</ResourceDictionary>

编辑 2

这可能看起来很疯狂,但是将 x:Class="DiagramDesigner.App" 更改为 x:Class="App" 为我修复了所有错误。看起来 VB.NET 不希望我在该属性中指定名称空间。

尝试将资源添加为

<ResourceDictionary Source="pack://application:,,,/DiagramDesigner;component/Resources/Themes/CommonThemes.xaml" />

或者从后面的代码中添加为

 Application.Current.Resources.MergedDictionaries.Clear();

var resource = new Uri("pack://application:,,,/DiagramDesigner;component/CultureDictionary.xaml");

Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = resource });

这是暗中拍摄,但将 x:Class="DiagramDesigner.App 更改为 x:Class="App"

;-)