Good day.

I'm trying to write an application using the mvvm pattern with the participation of the Caliburn.Micro framework. My task: in MainView.xaml, besides the MainViewModel, attach another view model to MenuItem , where Header="Файл" . It is described in the separate FileMenuViewModel class. Binding MenuItem to viewmodel in xaml I do this:

 <MenuItem cal:View.Model="{Binding FileMenuViewModel, Mode=TwoWay}" Header="Файл" Height="22" Margin="4,0,0,0"> 

, but when you click any of the menu buttons from the MenuItem "File" in the form, an Exception crashes, for example, like this:

"No target found for method OpenFileWindow."

As I understand it, Caliburn Micro cannot find this stupid Target from this: cal: View.Model property, in which the ViewModel or any other element that binds to the View is indicated.

Here is my project:

https://yadi.sk/d/Z9paO0yfuqwWc

So much googling and still can not find: why CaliBurn. Micro can not find Target and how to fix it?

Please help (and do not attack, pliz))))), but for the time being do not offer me options for which I will have to inherit from the class Bootstrapper AppBootStrapper that I have to take Silverlight or Prism from which I absolutely do not want to have case (so hard for me to study).

  • If it's hard for you to study, why don't you write WPF in stock? Everything is easier there. - VladD
  • (At us from understanding in Caliburn.micro, probably, only @Squidward.) - VladD
  • @VladD, as it were, yes, but one guy I turned to for help says that wpf with CaliBurn Micro is easier. In the sense that this generally eliminates the need to declare events and handlers for these events, implement the IPropertyChanged interface, etc. manually. But who could know that in order to add another additional view model besides MainViewMode, you need to go into the AppBootStrapper class and from there declare additional view models that, on the one hand, this is not so convenient. And besides yuzanya, third-party BootStrapper <IShell> or something like that, the docks do not say how else you can. - Minion Skywalker
  • Well, you see that it is simpler in one thing - more difficult in another :) Let's wait for the qualified responders. - VladD

1 answer 1

It turns out that Caliburn.Micro actually sets up a view class class for all components of the form (user control) of a particular window, which is specified and called through the class constructor AppBootStrapper. To change the view model from user control, you need to change the data context property with respect to the control tag (form component) where it is used for your new view model. Thus, to set a new model, the class of which is defined, you need to write as follows:

 <Grid.DataContext> <VModels:TextInOutViewModel /> </Grid.DataContext> 

where VModels is an alias that points to the namespace where you usually store classes, each of which represents a view model