我是WPF的新手。我正在使用运行良好的通知proyect(WPFGrowlingNotifications),但是当我从我的主项目引用该项目时问题就出现了。我一直得到“无法找到静态资源'CloseButton'” 这是CloseButton样式:
(?>(^)?)
以下是它的名称:
<Style x:Key="CloseButton" TargetType="{x:Type Button}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="MinHeight" Value="16"/>
<Setter Property="MinWidth" Value="16"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Border x:Name="Border" CornerRadius="3" BorderThickness="0" ClipToBounds="False" Background="{StaticResource CloseNormal}" BorderBrush="{StaticResource NormalBorderBrush}">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Opacity=".4" BlurRadius="5" Color="Black"/>
</Border.Effect>
<Grid>
<Image Source="pack://application:,,,/Resources/close.png" IsHitTestVisible="False" Margin="2">
<Image.Effect>
<DropShadowEffect Direction="90" ShadowDepth="1" BlurRadius="1"/>
</Image.Effect>
</Image>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource CloseOver}" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource ClosePressed}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
</Trigger>
<Trigger Property="IsDefaulted" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这是在app.xml中
<Button x:Name="CloseButton" Grid.Column="1" Width="16" Height="16" HorizontalAlignment="Right" Margin="0,0,12,0" Style="{StaticResource CloseButton}"/>
单独运行项目时没有问题。我认为当我从其他proyect进行引用时,app.xml会以某种方式被忽略......
答案 0 :(得分:2)
您需要引用程序集作为ResourceDictionary源。
<ResourceDictionary Source="pack://application:,,,/WPFGrowlingNotifications;component/Resources/ButtonStyle.xaml"/>
请注意&#34; WPFGrowlingNotifications &#34;源字符串的药水。这需要是一个完全限定的程序集名称。您可以阅读有关Pack URI语法here的更多信息。具体来说,您需要阅读Resource File Pack URIs - Referenced Assemblies部分。