2015-06-01 31 views
0

有兩個行爲根據其容器按鈕的IsEnabled屬性更改路徑的不透明度。我有幾個按鈕,我想重複使用這兩種行爲,因爲它們的容器具有相同的路徑。我怎麼做?如何重用行爲?

<Button x:Name="buttonConcentration"> 
    <Canvas Width="42.6667" Height="42.6667"> 
     <Path Opacity="0.2" Width="42.835" Height="42.696" Stretch="Fill" 
     Data="..." UseLayoutRounding="False"> 
      <Interactivity:Interaction.Behaviors> 
       <Core:DataTriggerBehavior 
        Binding="{Binding IsEnabled, ElementName=buttonConcentration}" 
        Value="False"> 
        <Core:ChangePropertyAction PropertyName="Opacity" Value="0.2"/> 
       </Core:DataTriggerBehavior> 
       <Core:DataTriggerBehavior 
        Binding="{Binding IsEnabled, ElementName=buttonConcentration}" 
        Value="True"> 
        <Core:ChangePropertyAction PropertyName="Opacity" Value="1"/> 
       </Core:DataTriggerBehavior> 
      </Interactivity:Interaction.Behaviors> 
     </Path> 
    </Canvas> 
</Button> 

回答

1

嘗試在您的Window.Resources上設置它。

在這段代碼也許工作,你就可以達到你期待什麼:

<Window.Resources> 
    <Button x:Key="myButtonConcentration" x:Shared="False"> 
     <Canvas Width="42.6667" Height="42.6667"> 
      <Path Opacity="0.2" Width="42.835" Height="42.696" Stretch="Fill" 
      Data="..." UseLayoutRounding="False"> 
       <Interactivity:Interaction.Behaviors> 
        <Core:DataTriggerBehavior 
         Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" 
         Value="False"> 
         <Core:ChangePropertyAction PropertyName="Opacity" Value="0.2"/> 
        </Core:DataTriggerBehavior> 
        <Core:DataTriggerBehavior 
         Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" 
         Value="True"> 
         <Core:ChangePropertyAction PropertyName="Opacity" Value="1"/> 
        </Core:DataTriggerBehavior> 
       </Interactivity:Interaction.Behaviors> 
      </Path> 
     </Canvas> 
    </Button> 
</Window.Resources> 

<Grid> 
    <ContentControl Name="MyButton1" Content="{StaticResource myButtonConcentration}" /> 
    <ContentControl Name="MyButton2" Content="{StaticResource myButtonConcentration}" /> 
</Grid> 
+0

OK,但不會的ElementName需要是某種相對路徑(這似乎我不能上班)? –

+0

我會編輯它。給我幾分鐘。 –

+0

任何更新是否有效? –