AutowireViewModel在Prism模块中不起作用
问题描述:
我确定我在这里做错了什么,但是当我在模块中定义的视图中设置AutowireViewModel attach属性时,它无法自动连接视图模型。我没有看到实例化的视图模型。我的样本项目在github上(见下文)AutowireViewModel在Prism模块中不起作用
<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
请忽略硬编码的路径在https://github.com/rohits79/PrismAutoWire/blob/master/Prism%20App/Prism%20App/Bootstrapper.cs#L34
答
你已经得到了命名空间是错误的。
namespace MainModule
[...]
public partial class ToolbarWindow
视图有居住在Whatever.Views
和Whatever.ViewModels
视图模型,如果你不想更改默认分辨率方案。
所以移动ToolbarWindow
到MainModule.Views
,你很好去。
BTW:IView
了,不再与棱镜6
+0
这对我来说是个诡计。我有我的名字空间作为Something.View和Something.ViewModel,所以AutoWire无法正常工作。一旦我将它们复制到Views和ViewModels,成功了! –
需要的是一个ItemsControl的一个ItemTemplate使用的用户控件? – Clemens
不,请查看github上的源代码 –