静态资源无法解析

时间:2014-09-25 07:34:02

标签: c# wpf mahapps.metro

我正在尝试在我的会计系统中实施MahApps风格我按照此处所需的步骤使用我使用的链接MahApps

以下是我遇到的错误代码,我在此处无法解析资源appbar_cupcake是代码

<Controls:MetroWindow x:Class="Hassab_Accounting_System.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>

</Grid>
<Controls:MetroWindow.RightWindowCommands>
<Controls:WindowCommands>
<Button Content="settings" />
<Button>
  <StackPanel Orientation="Horizontal">
    <Rectangle Width="20" Height="20"
               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button},    Path=Foreground}">
      <Rectangle.OpacityMask>
        <VisualBrush Stretch="Fill"
                     Visual="{StaticResource appbar_cupcake}" />
      </Rectangle.OpacityMask>
    </Rectangle>
    <TextBlock Margin="4 0 0 0"
               VerticalAlignment="Center"
               Text="deploy cupcakes" />
  </StackPanel>
  </Button>
  </Controls:WindowCommands>
  </Controls:MetroWindow.RightWindowCommands>
  </Controls:MetroWindow>
            `
   ![here is the error ][2]

Exception

1 个答案:

答案 0 :(得分:2)

假设您尚未执行此操作,因为问题中未包含此内容,请确保在文件顶部的ResourceDictionary中将资源文件包含在您的案例icon.xaml中。

类似的东西:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Resource/icon.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

或者像App.xaml一样:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
             <ResourceDictionary Source="/Resource/icon.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>