ViewModelBinder XAML

Topics: Conventions
Dec 20, 2011 at 2:15 PM
Edited Dec 20, 2011 at 2:46 PM

Since i find the whole auto convention thing pretty useful but am doing this through code(will not get into why..)

i was wondering if something like this is possible in XAML:

View is automatically binded to the ViewModel...and any button click is nicelly mapped to the CanClick property and Click Method by Caliburn Micro.


Not let's suppose that this View contains another grid...which contains more buttons.

And let's say i want to do the same magic binding for all these buttons...but i don't want the actions to be binded to the Can_MethodName and MethodName methods on the current ViewModel...but rather an instance property on the ViewModel.


So we have

MainPageView which caliburn micro has "magically" binded to MainPageViewModel.

MainPageView contains a Grid with 5 Buttons.I want those clicks to be binded to MainPageViewModel.ButtonActions

ButtonActions is an instance of a class which has the required methods who's names match the buttons name.

Can i use the caliburn:View...and other attached properties in XAML to somehow make this work?


i'm guessing there's a dependency property in caliburn micro which can be used to do the following:

ViewModelBinder.Bind(viewModel, view, null);

Where view is the FrameworkElement and well...i provide the viewModel with binding :)

Dec 20, 2011 at 3:21 PM

Try the Bind.Model attached property. You can put this on any view and provide a value (or binding) for the view model.

Dec 20, 2011 at 5:48 PM

Ah was just going to mark it as fixed.

EisenbergEffect's suggestion is the right one :)