找不到资源词典

时间:2015-06-29 11:05:26

标签: .net wpf xaml resourcedictionary

所以下面的图片说明了一切。 WPF找不到某些的xaml文件。我试过移动它们,但无济于事。所有这些都将其Build Action设置为Page和Custom Tool设置为MSBuild:Compile。不知道我在这里缺少什么。

Errors Snapshot

修改

根据要求,这里有两个示例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不希望我在该属性中指定命名空间。

2 个答案:

答案 0 :(得分:1)

尝试添加资源

<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});

答案 1 :(得分:1)

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

- )