locked
RoutedCommand problem RRS feed

  • Question

  • We are currently creating a command (ICommand / RoutedCommand) driven application.

    There are UI element which answer to the commands (through some command bindings and execute / can execute handers) and some command source (button, menu item and their like).

     

    Now here is the problem, we would like to use property dialogs (i.e. floating windows) with some more command source on it (button, slider and the like).

    But the command on this dialog (window with the Window.Owner property set) never make it to the CanExecute handler of the main window.

    As a result all command source are disabled and never execute.

     

    Initially we found a "fix/hack/workaround" which looks like that (pseudo code)

     

    Code Snippet

    foreach (Visual v in EnumVisual(mainwindow))

    {

       UIElement element = v as UIElement;

       if (element != null)

         propertydialog.CommandBindings.AddRange(element.CommandBindings);

    }

     

     

    as you can see we just add all the command binding from the main window to the property dialog.

    but this is unsatisfactory as new element could be added or removed afterward to the main window (think TabControl, ListBox or simply the result of a new command) and they will never be targeted by the commands binding of the property dialog.

     

    Is my explanation meaningfull?
    What can I do to have my commands onthe property dialog track the focused element on the main window?
    Could you offer any tip?

    Wednesday, August 8, 2007 2:33 AM

Answers