我希望在此对话框中某些文本框的内容发生更改时启用“应用”对话框按钮。
以下是我提出的建议:
<Window.Resources>
<ResourceDictionary>
...
<Style x:Key="SettingTextBoxStyle" TargetType="{x:Type TextBox}">
<Style.Triggers>
<EventTrigger RoutedEvent="TextBox.TextChanged" >
<!-- I need something like this -->
<Setter Property="ApplyButton.IsEnabled" Value="True" />
</EventTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</Window.Resources>
<!-- in a galaxy far far away -->
<StackPanel>
...
<TextBox Style="{StaticResource SettingTextBoxStyle}" Text="{Binding Source={x:Static settings:Settings.Default}, Path=OutputFile}" />
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="OK" Width="100" Click="OK_Click"/>
<Button Content="Cancel" Width="100" Click="Cancel_Click" />
<Button Content="Apply" Name="ApplyButton" Width="100" Click="Apply_Click"/>
</StackPanel>
如何在事件触发器中触及ApplyButton.IsEnabled
属性?
我是否应该在后面的代码中使用相同的TextChanged
事件处理程序?
还是其他什么?
答案 0 :(得分:0)
你可以试试这个:
<Grid>
<TextBox Name="textBox" Height="28" VerticalAlignment="Top" HorizontalAlignment="Left" Width="95" >
<TextBox.Triggers>
<EventTrigger RoutedEvent="TextBox.TextChanged">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="button1" Storyboard.TargetProperty="(Button.IsEnabled)">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBox.Triggers>
</TextBox>
<Button Height="26" Width="150" IsEnabled="false" Name="button1">Button</Button>
</Grid>