Rohit Sharma
Rohit Sharma

Reputation: 6500

AutowireViewModel does not work when inside a Prism Module

I am sure I am doing something wrong here, but when I set AutowireViewModel attach property in the view defined in a module, it cannot auto-wire up the view model. I do not see the view model instantiated. My sample project is at github (see below)

<UserControl x:Class="MainModule.ToolbarWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mvvm="clr-namespace:Microsoft.Practices.Prism.Mvvm;assembly=Microsoft.Practices.Prism.Mvvm.Desktop"
         mvvm:ViewModelLocator.AutoWireViewModel="True"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
    <Label>Test</Label>
    <Label Content="{Binding Name}"></Label>
</StackPanel>

https://github.com/rohits79/PrismAutoWire/tree/master/Prism%20App/MainModule

Please ignore the hardcoded path at https://github.com/rohits79/PrismAutoWire/blob/master/Prism%20App/Prism%20App/Bootstrapper.cs#L34

Upvotes: 2

Views: 3524

Answers (1)

Haukinger
Haukinger

Reputation: 10873

You've got the namespaces wrong.

namespace MainModule

[...]

public partial class ToolbarWindow

The view has to reside in Whatever.Views and the view model in Whatever.ViewModels if you don't want to change the default resolution scheme.

So move ToolbarWindow into MainModule.Views and you're good to go.

BTW: IView isn't needed anymore with Prism 6

Upvotes: 6

Related Questions