![](/img/trans.png)
[英]How to change the MenuItem Header according to the value selected in its submenu?
[英]How to change menuitem header by selected tabcontrol item
在我的 WPF windows 表單中,我有 menuitem 和 TabControl。 我想更改目錄header Menuitem的Menuitem當TabControl項目選擇時。 如果有可能。 如何在 C# 中做到這一點?
謝謝
如果需要,您可以在沒有任何代碼或ViewModel
使用的情況下執行此操作。
我們只需將MenuItem
的Header
屬性綁定到選定的選項卡項 header。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Menu Grid.Row="0" Height="32">
<MenuItem Header="{Binding ElementName=MyTabControl, Path=SelectedItem.Header}"/>
</Menu>
<TabControl Grid.Row="1" Name="MyTabControl">
<TabItem Header="Tab1Header"/>
<TabItem Header="Tab2Header"/>
</TabControl>
</Grid>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.