2011-04-07 71 views
1

我有一个针对性的WPF风格:WPF风格适用不一致

<Style x:Key="ImgFadeStyle" 
     TargetType="Image"> 
    <Style.Triggers> 
     <Trigger Property="IsEnabled" Value="false"> 
      <Setter Property="Opacity" Value=".5" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

我把它应用到一些图片:

<Image Name="imgFirst" 
    Grid.Column="0" 
    Style="{StaticResource ImgFadeStyle}" 
    Source="pack://application:,,,/AppGUI;component/Images/Temp/resultset_first.png" 
    ToolTip="First" 
    MouseLeftButtonUp="imgFirst_MouseLeftButtonUp" /> 

<Image Name="imgLast" 
    Grid.Column="6" 
    Style="{StaticResource ImgFadeStyle}" 
    Source="pack://application:,,,/AppGUI;component/Images/Temp/resultset_last.png" 
    ToolTip="Last" 
    MouseLeftButtonUp="imgLast_MouseLeftButtonUp" /> 

在代码隐藏,我设置了IsEnabled属性设置为“真”或者“假”。第一张图片总是按预期做出反应。第二张图片对属性更改没有反应。有谁知道什么是错的?

谢谢。

+0

H.B.很可能是正确的。您可以使用[WPF Visualizer](http://blogs.msdn.com/b/jgoldb/archive/2010/05/25/wpf-visualizer-in-visual-studio-2010.aspx)轻松验证。如果您在点击一个断点后(例如在imgLast_MouseLeftButtonUp中)在监视窗口中有imgLast,则可以单击放大镜。它会列出右侧的属性,它会告诉你不透明度属性的来源。 – CodeNaked 2011-04-08 00:30:41

回答

2

这可能是由Dependency Property value precedence引起的问题,如果您明确地将最后一张图片的Opacity设置为0,则可能会覆盖样式的成果。

+0

好想法,但不透明度不设置在任何其他位置。 – Sako73 2011-04-07 20:22:38

+0

那么,没有理由不去查看你的代码。我很确定上下文有问题。无法真正告诉你任何事情只是看着这个。 – 2011-04-07 20:25:42