我有一個TabControl包含兩個TabItems(讓我們稱之爲「A」和「B」)的窗口。選項卡A有幾個ContextMenus:我希望每個MenuItem將TabItem更改爲Tab B.理想情況下,我會編寫一個MenuItem模板,在選擇MenuItem時切換選項卡。這可能嗎?WPF共享EventTrigger
編輯: 我結束了使用的解決方案依賴於在ContextMenus的MenuItems從定義click事件和處理程序基本樣式推導:
<Window.Resources>
<ResourceDictionary>
<Style TargetType="MenuItem" x:Key="ContextMenuItemBase">
... (various stylings)
<EventSetter Event="Click" Handler="MenuItem_Clicked"/>
</Style>
</ResourceDictionary>
</Window.Resources>
我叫我要到標籤控件和標籤項目開關:
<TabControl x:Name="tcTabs">
...
<TabItem Header="Results" x:Name="tiResultsTab">
然後在MainWindow.xaml.cs代碼隱藏文件:
private void MenuItem_Clicked(object sender, RoutedEventArgs e)
{
tcTabs.SelectedItem = tiResultsTab;
}
目前尚不清楚您要求的是什麼......標籤A的拼寫菜單需要將標籤更改爲顯示標籤B.您是否可以改寫/寫入您的位置? – OmegaMan
是......當按下其中一個菜單項時,選項卡A的上下文菜單需要更改選項卡以顯示選項卡B. – riqitang
什麼阻止您訂閱活動並切換到表B? – OmegaMan