2015-07-10 84 views
1

我有两个按钮。如何在使用xaml单击第一个按钮后启用第二个按钮。触发按钮启用

<Window.Resources> 
    <Style x:Key="NewButtonStyle" TargetType="{x:Type Button}"> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding ElementName=SecondButton, Path=IsEnabled,Mode=TwoWay}" Value="True"> 
       <Setter Property="IsEnabled" Value="True"/> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 
</Window.Resources> 
<Grid> 
    <Button x:Name="FirstButton" Content="Button" HorizontalAlignment="Left" Margin="10,22,0,0" VerticalAlignment="Top" Width="75" Style="{StaticResource NewButtonStyle}"/> 
    <Button x:Name="SecondButton" Content="Button" HorizontalAlignment="Left" Margin="105,22,0,0" VerticalAlignment="Top" Width="75" IsEnabled="False"/> 
</Grid> 

回答

1

你必须为了使用Interaction.Triggers和ChangePropertyAction(System.Windows.Interactivity和Microsoft.Expression.Interactions)

<Button x:Name="FirstButton" Content="Button" HorizontalAlignment="Left" Margin="10,22,0,0" VerticalAlignment="Top" Width="75"> 
    <i:Interaction.Triggers> 
     <i:EventTrigger EventName="Click"> 
      <ei:ChangePropertyAction TargetName="SecondButton" PropertyName="IsEnabled" Value="True"/> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</Button> 
<Button x:Name="SecondButton" Content="Button" HorizontalAlignment="Left" Margin="105,22,0,0" VerticalAlignment="Top" Width="75" IsEnabled="False"/> 
添加两个引用