當我按下Alt + S時,此MenuItem不會切換到檢查狀態,爲什麼?在MenuItem的IsCheckable =「True」中綁定鍵的問題,爲什麼?
<Menu>
<MenuItem Header="_Other">
<MenuItem
Header="_Show Expanded Names ?"
IsCheckable="True"
StaysOpenOnClick="True"
InputGestureText="Alt+S"
IsChecked="{Binding ShowExpandedName}" />
</MenuItem>
</Menu>
注意:ShowExpandedName在DataContext中定義如下。當我用鼠標點擊它時,MenuItem被正確檢查。
bool _ShowExpandedName;
public bool ShowExpandedName
{
get { return _ShowExpandedName; }
set
{
if (value != _ShowExpandedName)
{
_ShowExpandedName = value;
this.NotifyPropertyChanged("ShowExpandedName");
}
}
}
對不起,我忘了解釋ShowExpandedName是NotifyPropertyChange。我編輯了我的問題來澄清這一點。 – Nestor 2010-11-23 13:31:42
啊...好吧然後:第。現在,在您對Alt + S的治療中,您是否有機會直接更改_ShowExpandedName變量?這將繞過通知,因此你的行爲。更好地使用Set()函數 – David 2010-11-23 13:36:06