【问题标题】:Cannot find resource dictionaries找不到资源字典
【发布时间】:2015-06-29 11:05:26
【问题描述】:

所以下面的图片说明了一切。 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 不希望我在该属性中指定命名空间。

【问题讨论】:

  • 假设您已经完成了清理和重建?这总是用 WPF 为我解决它
  • @Nico:这对我不起作用。我也重新启动了VS。需要注意的是,问题仅限于一些而不是所有文件。
  • 您使用的是网络共享还是外部存储?
  • 工作文件和非工作文件之一的内容是什么?
  • 请在示例项目中一一尝试资源字典。检查是否正常工作。

标签: .net wpf xaml resourcedictionary


【解决方案1】:

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

;-)

【讨论】:

  • 这正是解决方案。你怎么猜得这么准? :-)
  • @dotNET 当然,请随意回答您自己的问题,我将删除这个滑稽的帖子。或者,如果您愿意,可以将我的标记为答案。 :-)
【解决方案2】:

尝试将资源添加为

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

【讨论】:

  • 完全相同的结果。适用于它在快照中工作的那些,对其他人显示错误。
  • 如果,这种风格在 xaml 中不起作用,那么它如何在 Code Behind 中起作用。
  • 你只是在确认?那么这是答案还是评论?顺便说一句,我认为您的大写锁定键可能在您上次发表评论时被切换了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多