AutowireViewModel 在 Prism 模块内时不起作用
AutowireViewModel does not work when inside a Prism Module
我确定我在这里做错了什么,但是当我在模块中定义的视图中设置 AutowireViewModel attach 属性 时,它无法自动连接视图模型。我没有看到实例化的视图模型。我的示例项目位于 github(见下文)
<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
就可以了。
顺便说一句:Prism 6 不再需要 IView
我确定我在这里做错了什么,但是当我在模块中定义的视图中设置 AutowireViewModel attach 属性 时,它无法自动连接视图模型。我没有看到实例化的视图模型。我的示例项目位于 github(见下文)
<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
就可以了。
顺便说一句:Prism 6 不再需要 IView