[英]WPF / XAML: Change TabControl SelectedItem on Button Press
我正在尋找針對以下問題的純XAML解決方案:
我有一個按鈕和一個選項卡控件。 當我按下按鈕時,選項卡控件應顯示某個選項卡(因此按鈕應更改Tabcontrol的SelectedIndex)。 我知道如何用后面的代碼解決這個問題,但這不是我想要的。
是否可以使用觸發器來做到這一點?
它對此進行了測試,並且可以正常工作
請注意不要使用過大的SelectedIndex。 它們從0開始。
<Window.Resources>
<Storyboard x:Key="OnClick1">
<Int32AnimationUsingKeyFrames
Storyboard.TargetProperty="(Selector.SelectedIndex)"
Storyboard.TargetName="tabControl">
<EasingInt32KeyFrame KeyTime="0" Value="1"/>
</Int32AnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
<BeginStoryboard Storyboard="{StaticResource OnClick1}"/>
</EventTrigger>
</Window.Triggers>
如果需要,我可以發送完整的代碼,只需在評論中提問
如果需要,這里是完整代碼的鏈接: http ://1drv.ms/1SuA8pn
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.