RoutedUICommand PreviewExecuted Bug?

前端 未结 2 473
刺人心
刺人心 2021-01-03 03:21

I\'m building an application using the MVVM design pattern and I want to make use of the RoutedUICommands defined in the ApplicationCommands class. Since the CommandBindings

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 03:56

    I build the following workaround, to obtain the missing ContinueRouting behavior:

    foreach (CommandBinding cb in CommandBindings)
    {
        if (cb.Command.Equals(ApplicationCommands.Save))
        {
            ExecutedRoutedEventHandler f = null;
            f = (sender, e) =>
            {
                if (IsModified)
                {
                    BindingExpression be = rtb.GetBindingExpression(TextBox.TextProperty);
                    be.UpdateSource();
    
                    // There is a "Feature/Bug" in .Net which cancels the route when adding PreviewExecuted
                    // So we remove the handler and call execute again
                    cb.PreviewExecuted -= f;
                    cb.Command.Execute(null);
                }
            };
            cb.PreviewExecuted += f;
        }
    }
    

提交回复
热议问题