根據描述,我有 aToggleButton和 a Button。
Button切換時出現,取消ToggleButton切換時消失。
我想在單擊時觸發該ToggleButton屬性IsChecked并將其設定為 false Button。我知道應該用觸發器來完成,但我不知道怎么做。
<ToggleButton x:Name="EditBtn" VerticalAlignment="Top" Focusable="False">
<Button VerticalAlignment="Bottom" Height="24" Width="24"
Visibility="{Binding ElementName=EditBtn, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"
Command="{Binding ElementName=InfoList, Path=DataContext.SaveCommand}" CommandParameter="{Binding}" >
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource ButtonTransparentStyle}">
<Style.Triggers>
<!-- Something here? -->
</Style.Triggers>
</Style>
</Button.Style>
</Button>
uj5u.com熱心網友回復:
這是使用 StoryBoard 的選項:
<Button VerticalAlignment="Bottom" Height="24" Width="24"
Visibility="{Binding ElementName=EditBtn, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"
Command="{Binding ElementName=InfoList, Path=DataContext.SaveCommand}" CommandParameter="{Binding}" >
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames
Storyboard.TargetName="EditBtn"
Storyboard.TargetProperty="(ToggleButton.IsChecked)">
<DiscreteBooleanKeyFrame
KeyTime="00:00:00"
Value="False"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
您還可以系結 ToggleButton 的 IsChecked 屬性,只需修改 ViewModel 中的附加屬性(在您的按鈕命令觸發的 void 中)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421950.html
標籤:
