2016-05-30 6 views
1

Ich bin mir sicher, dass ich hier etwas falsch mache, aber wenn ich die AutowireViewModel Eigenschaft in der in einem Modul definierten Ansicht anhänge, kann das Ansichtsmodell nicht automatisch verbunden werden. Ich sehe das Ansichtsmodell nicht instanziiert. Mein Beispielprojekt bei Github ist (siehe unten)AutowireViewModel funktioniert nicht in einem Prism-Modul

<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

Bitte ignorieren, den fest verdrahteten Weg bei https://github.com/rohits79/PrismAutoWire/blob/master/Prism%20App/Prism%20App/Bootstrapper.cs#L34

+0

Ist das Usercontrol in einem ItemTemplate eines Itemscontrol verwendet? – Clemens

+0

Nein, bitte schauen Sie sich den Quellcode auf dem GitHub –

Antwort

3

Sie haben falsche Namespaces bekam.

namespace MainModule 

[...]

public partial class ToolbarWindow 

Die Ansicht hat in Whatever.Views und das View-Modell in Whatever.ViewModels wohnen, wenn Sie wollen nicht das Schema Standardauflösung ändern.

So verschieben Sie ToolbarWindow in MainModule.Views und Sie sind gut zu gehen.

BTW: IView benötigt wird, um nicht mehr mit Prism 6

+0

Dies hat den Trick für mich. Ich hatte meine Namespaces als Something.View und Something.ViewModel, damit AutoWire nicht funktionierte. Sobald ich sie zu Views und ViewModels pluralisiert habe, Erfolg! –