注意:匿名事件处理函数
if (button != null && button.m_defaultMenuItem != menuItem)
{
button.m_defaultMenuItem.IsEnabledChanged += delegate(object o, DependencyPropertyChangedEventArgs args)
{
MenuItem currentMenu = o as MenuItem;
contentControl.IsEnabled = (bool)args.NewValue;
};
}
改为:
if (button != null && button.m_defaultMenuItem != menuItem)
{
button.m_defaultMenuItem.IsEnabledChanged += delegate(object o, DependencyPropertyChangedEventArgs args)
{
MenuItem currentMenu = o as MenuItem;
if (contentControl != null && button.m_defaultMenuItem == currentMenu)
contentControl.IsEnabled = (bool)args.NewValue;
};
}