2014-07-04 18 views
0

我放在Window.Resources我的图片样式的第一个按钮图像:图像样式没有应用到工具栏

<Style TargetType="{x:Type Image}"> 
     <Style.Triggers> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="Opacity" Value="0.3" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 

,我有一个工具栏:

 <ToolBarTray DockPanel.Dock="Top" Background="Transparent"> 
      <ToolBar Band="0" BandIndex="0" x:Name="ToolbarCATIAAccess" Background="{DynamicResource linearGradBrushHellaTitanMenu}"> 
       <Button Name="ButtonInsertIntoProduct"> 
        <Image x:Name="ImageInsertIntoProduct" Source="/HKBEStandardsFromPDMLibrary;component/Resources/InsertIntoCATIAProduct.png" 
          ToolTip="insert files into active CATIA Product"/> 
       </Button> 
       <Button Name="ButtonCopyFilesToWIN"> 
        <Image x:Name="ImageCopyFilesToWIN" Source="/HKBEStandardsFromPDMLibrary;component/Resources/CopyFilesToWIN.png" 
          ToolTip="copy files to WIN folder"></Image> 
       </Button> 
      </ToolBar> 
     </ToolBarTray> 

此样式适用于整个窗口以及其他应用程序中的所有图像。 但它不适用于工具栏中的第一个图像,并且哪一个先到达并不重要,不透明度不会在第一个设置。 如果我添加一个隐藏的(按钮)图像作为第一个图像到工具栏,它适用于第一个可见。

not working Style

... 
       <Button Name="ButtonCopyFilesToWIN_" Visibility="Collapsed"> 
        <Image x:Name="ImageCopyFilesToWIN_" Source="/HKBEStandardsFromPDMLibrary;component/Resources/CopyFilesToWIN.png" 
          ToolTip="copy files to WIN folder"></Image> 
       </Button> 
       <Button Name="ButtonInsertIntoProduct"> 
        <Image x:Name="ImageInsertIntoProduct" Source="/HKBEStandardsFromPDMLibrary;component/Resources/InsertIntoCATIAProduct.png" 
          ToolTip="insert files into active CATIA Product"/> 
       </Button> 
       ... 

working Style

是否有人在这里有一个想法可能是什么问题,能帮帮我吗? 谢谢

+1

做** **所有的工具栏按钮有'的IsEnabled = “假”' ?您是否验证了这一点(例如[Snoop](http://snoopwpf.codeplex.com/))? –

回答

1

我已经采取了您的资源和工具栏代码片段,并放置在简单的应用程序,以证明如果工作或不在我的例子中,它的行为,如我所料。我将不透明度更改为0,以便在图像消失时显而易见。

片段中的图片是我的示例,只是恢复到您的图片。通过在下面的片段中明确地设置图片中的IsEnabled属性,您会看到是否应用了样式。在这里,第二个图像消失(因为IsEnabled为false,并将样式上的不透明度设置为0),如果交换图像上的IsEnabled属性,以使第二个图像为true,并且第一个图像为false,则第一个图像消失。所以风格被应用于下面显示的基本示例应用程序。

<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Dictionary1.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window.Resources> 
<Grid> 
    <ToolBarTray DockPanel.Dock="Top" Background="Transparent"> 
     <ToolBar Band="0" BandIndex="0" x:Name="ToolbarCATIAAccess" > 
      <Button Name="ButtonInsertIntoProduct"> 
       <Image x:Name="ImageInsertIntoProduct" Source="scroll1.png" IsEnabled="True" 
         ToolTip="insert files into active CATIA Product"/> 
      </Button> 
      <Button Name="ButtonCopyFilesToWIN"> 
       <Image x:Name="ImageCopyFilesToWIN" Source="scroll2.png" IsEnabled="False" 
         ToolTip="copy files to WIN folder"></Image> 
      </Button> 
     </ToolBar> 
    </ToolBarTray> 
</Grid> 

只有其他代码示例应用程序(Dictionary1.xaml - 资源字典文件):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Style TargetType="{x:Type Image}"> 
    <Style.Triggers> 
     <Trigger Property="IsEnabled" Value="False"> 
      <Setter Property="Opacity" Value="0" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

+0

谢谢'玛'!所以这似乎是我的应用程序中的其他问题。或者,也许这只是一个问题,如果像我那样,在代码背后设置isenabled状态! – Crow1973

+0

奇怪!我在一个示例应用程序中添加了它,它可以工作。但不是在我目前的应用程序。但是再次感谢你'玛'。 – Crow1973