0
我需要爲菜單項創建一個上下文菜單。上下文菜單的可見性綁定到ViewModel。MenuItem可見性綁定的ContextMenu
當屬性更改爲true時,使用MVVM Light,即使沒有右鍵單擊菜單項,UI上也會出現上下文菜單。當值爲false時,我可以做些什麼來隱藏上下文菜單,並且只有在右鍵單擊時才能看到它?
private Boolean _IsEditable;
public Boolean IsEditable
{
get { return _IsEditable; }
set
{
if (_IsEditable == value) return;
_IsEditable = value;
RaisePropertyChanged("IsEditable");
}
}
<Menu DockPanel.Dock="Top">
<MenuItem Header="{Binding Menu.Business}" Visibility="{Binding allowUI, Converter={StaticResource BoolToVisConverter} }">
<MenuItem.ContextMenu>
<ContextMenu Visibility="{Binding Menu.IsEditable, Converter={StaticResource BoolToVisConverter} }">
<MenuItem>
<MenuItem.Header>
<TextBox Text="{Binding Menu.Business, UpdateSourceTrigger=PropertyChanged}" LostFocus="end_change_UI" />
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</MenuItem.ContextMenu>
</MenuItem>
</Menu>
感謝這麼簡單!完美的作品 –