What does MapToViewModelExtension do?

Dec 25, 2011 at 3:32 PM

Hello,

I don't understand the role of the custom markup extension: MapToViewModelExtension.

Is it an alternative to the following code to map a view to a view model?

        /// <summary>
        ///     This will allow the binding of the view model to the view
        /// </summary>
        [Export]
        public ViewModelRoute Binding
        {
            get
            {
                return ViewModelRoute.Create(
                    "ShellViewModel",
                    "ShellView");
            }
        }

The second snippet work well, while the first one doesn't display anything.

Am i misunderstanding something?

 

Regards,

Adrien.

Coordinator
Dec 27, 2011 at 11:01 AM

Yes. This is a way to connect to a view model in Xaml markup, so you can do something like:

<Grid DataContext="{MapToViewModel ViewModel=MyViewModel}"/>