0

I have an ViewModel containing 4 properties (Aaa, Bbb, Value, Focus) and button, that uses static command binding for simple client-only assignments:

<dot:Button Click="{staticCommand: Focus=="Aaa" ? (Aaa=Value) : (Bbb=Value)}" />>

This code works fine, but is not comfortable for more properties than Aaa, Bbb.

Not least it makes this button dependent on properties Aaa, Bbb, which complicate reuse button as UserControl.

Is possible to write some indirect assignment like this?

<dot:Button Click="{staticCommand: ViewModel[Focus]=Value}" />>
exyi
  • 452
  • 3
  • 12

3 Answers3

1

You can call method with atribute AllowStaticCommand in Viewmodel and solve you assignments there..

Code in markup of View will be more clear.

https://www.dotvvm.com/docs/tutorials/basics-static-command-binding/latest

KaMM
  • 51
  • 1
  • 5
0

I'm sorry, but it's not possible to write to any property by name, you'll probably have to stick with the conditional operator.

By the way, when you format the cascade like this, it does not look as terrifying when there is many options:

<dot:Button Click="{staticCommand: Focus=="Aaa" ? Aaa = Value :
                                   Focus=="Bbb" ? Bbb = Value :
                                   Focus=="Ccc" ? Ccc = Value :
                                                  Default = Value}" />

That does not however solve the problem with reusability. Maybe you could put those properties into an array and access them by index? Unfortunately, I'm not aware of any other solution.

exyi
  • 452
  • 3
  • 12
0

I have found this workaround. Instead of static binding I can directly write appropriate client side onclick event:

<dot:Button onclick="dotvvm.viewModels.root.viewModel[dotvvm.viewModels.root.viewModel.Focus()](dotvvm.viewModels.root.viewModel.Value())"  />