MVVM WPF Commands: Several Command Options

My problem may be more architectural than functional, but I'm trying to bind a TextBox to a command, and in this command I would like to pass a few parameters (i.e. a user object). Not sure how to do this declaratively (xaml).

ViewA (located on top of ViewModelA) it has a TextBox that is bound to CommandX

ViewB (located on top of ViewModelB) (this is actually another user control in the same Window as ViewA) When commandX fires, ViewModelB must execute some method. ViewModelB needs to be updated using several properties before it can execute this method.

My question is how can I structure my team / architecture so that ViewModelB has enough information to execute its method.

Note: ViewModelA has all the necessary information for ViewModelB to execute its method. but I don’t want to get it from there, because later I want CommandX to be executed from different views

Update

it looks like I can separately set the CommandParameter property, which could probably be due to a complex type in ViewModelA. This should be enough so that all the necessary properties are embedded in it.

awesome

It worked! this is what the parmeter property looks like ViewA

    public ExecuteQueryCommandParameters ExecuteQueryParameters {
        get {
            var p = new ExecuteQueryCommandParameters();
            p.AllColumns = ColumnsMaster;
            p.DatabaseName = SelectedDatabase;
            p.ServerName = SelectedServer;
            p.TopRows = 20;
            p.ViewModelName = "MainDataView";

            return p;
        }
    }

and button implementation

<Button Command="{Binding ExecuteQuery}" CommandParameter="{Binding ExecuteQueryParameters}">Top 20</Button>

Update

. . , . , , . , ?

+3
1

:

, , "MyCustomCommandParameters" .

, XAML ViewModelA.

ViewModelA MyCustomCommandParameters.

ViewB DependencyProperty MyCustomCommandParameters. ViewModelB.

XAML ViewB "MyCustomCommandParameters" ViewModelA "MyCustomCommandParameters" .

, : ViewModelA ViewModelB XAML, .

+1

All Articles