PsimApp创建后,加入xaml 代码
d:DataContext="{d:DesignInstance Type=viewmodels:MainWindowViewModel}"
编译生成时,提示错误:
属性“DataContext”必须位于默认的命名空间或元素命名空间“http://schemas.microsoft.com/winfx/2006/xaml/presentation”中。 行 7 位置 70.
解决办法
<Window
...
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
...
/>
完整代码如下
<Window x:Class="Expert3DPipeline.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
xmlns:viewmodels="clr-namespace:Expert3DPipeline.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignInstance Type=viewmodels:MainWindowViewModel}"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525" >
<Grid>
<DockPanel LastChildFill="True">
<Button Content="Run" Command="{Binding RunTaskCommand}" DockPanel.Dock="Bottom"/>
<wv2:WebView2/>
</DockPanel>
</Grid>
</Window>