Note that there are some explanatory texts on larger screens.

plurals
  1. POCommand binding in multiwindow WPF app
    text
    copied!<p>My application can have multiple designer windows. Each window constitutes of several user controls which communicates dynamically with the help of RelayCommands. I created the following class as the backbone of the commanding infrastructure.</p> <pre><code>public static class Commands { public static readonly RoutedCommand EntityEditRequest = new RoutedCommand(); public static RelayCommand EntityEditorChangeRequest; public static RelayCommand XMLUpdateRequest; public static RelayCommand SaveRequest; } </code></pre> <p>Each viewmodel for the user controls will do something like this in the constructor</p> <pre><code> public XMLEditorViewModel() { Commands.Commands.SaveRequest = new RelayCommand(Save_Executed); Commands.Commands.XMLUpdateRequest = new RelayCommand(UpdateXML); } </code></pre> <p>However, I completely missed the point that the application can have multiple windows. When each window is opened the static Commands are set for that particular window. </p> <p>Example:</p> <p>Window A is opened-the constructors for the usercontrols set the RelayCommands and all is well.</p> <p>Window B opened-the constructors for the usercontrols set the RelayCommands. Window A's command binding is lost!</p> <p>So when I change the tab to Window A(the windows are tabbed) no commands are working.</p> <p>I need some idea so that when I change the tab the active window always sets the commands. I can try to put the commanding in tab_selection_changed event, but somehow it is looking bad to me. Is there a proper way to do this? Any help is much appreciated.</p> <p>Edit:</p> <p>The question proved a bit confusing among the readers. I am not trying to make multiple subscribers for a command. At any given point only one window is active. This window consists several user controls-some of them loaded dynamically with the help of commands; but each command is handled by a single view model class-so no multi subscribers. My problem is the application can load multiple windows in tabs-only one window is active at any given point-but the user can do to a different tab and make another window active. As the view model constructor assigns the static RelayCommands, when each new window is loaded the static command is set to a new binding. </p> <p>Window A opened-window A view model constructor sets the static command bind to its object command handler. Window A is active. Commanding is fine.</p> <p>Window B loaded-window B view model constructor sets the static command bind to its object command handler. Window B is active. Commanding is fine.</p> <p>Now, User select the Window A tab to set the Window A as active. Commanding wont work. Of course it wont as the Command is bind to Window B command handler.</p> <p>Theoretically static commands can handle the scenario as at any given point there will be only one active window. But how??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload