ViewModel 位置到子文件夹(XAML,命名空间)
ViewModel location into sub-folder (XAML, namespace)
进入MainWindow.xaml我有:
<Window x:Class="LayoutMVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ResizeMode="NoResize"
xmlns:local="clr-namespace:LayoutMVVM"
xmlns:veiwmodels="clr-namespace:LayoutMVVM.ViewModels"
xmlns:views="clr-namespace:LayoutMVVM.Views"
Title="Layout" Height="750" Width="650">
进入Windows.Resources我正在绑定dataContext:
<Window.Resources>
<DataTemplate x:Name="SettingsTemp" DataType="{x:Type veiwmodels:SettingsModel}">
<views:SettingsView DataContext="{Binding}" />
</DataTemplate>
</Window.Resources>
但是当我的其他模型和视图位于如下子文件夹中时:
我做不到:
<DataTemplate x:Name="OpenTemp" DataType="{x:Type ViewModels:Open.OpenModel}">
<views:Open.OpenView DataContext="{Binding}" />
</DataTemplate>
或LayoutMVVM.ViewModels.Open.OpenModel
或LayoutMVVM/ViewModels/Open/OpenModel
您应该在 header 控件中添加新的:
xmlns:veiwmodelsOpen="clr-namespace:LayoutMVVM.ViewModels.Open
或者您可以将 OpenModel 的命名空间设置为 LayoutMVVM.ViewModels (not LayoutMVVM.ViewModels .打开).
我想没有别的办法了。
进入MainWindow.xaml我有:
<Window x:Class="LayoutMVVM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ResizeMode="NoResize"
xmlns:local="clr-namespace:LayoutMVVM"
xmlns:veiwmodels="clr-namespace:LayoutMVVM.ViewModels"
xmlns:views="clr-namespace:LayoutMVVM.Views"
Title="Layout" Height="750" Width="650">
进入Windows.Resources我正在绑定dataContext:
<Window.Resources>
<DataTemplate x:Name="SettingsTemp" DataType="{x:Type veiwmodels:SettingsModel}">
<views:SettingsView DataContext="{Binding}" />
</DataTemplate>
</Window.Resources>
但是当我的其他模型和视图位于如下子文件夹中时:
我做不到:
<DataTemplate x:Name="OpenTemp" DataType="{x:Type ViewModels:Open.OpenModel}">
<views:Open.OpenView DataContext="{Binding}" />
</DataTemplate>
或LayoutMVVM.ViewModels.Open.OpenModel
或LayoutMVVM/ViewModels/Open/OpenModel
您应该在 header 控件中添加新的:
xmlns:veiwmodelsOpen="clr-namespace:LayoutMVVM.ViewModels.Open
或者您可以将 OpenModel 的命名空间设置为 LayoutMVVM.ViewModels (not LayoutMVVM.ViewModels .打开).
我想没有别的办法了。