2014-07-04 20 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