关键代码:
bash
d:DataContext="{d:DesignInstance Type=local:MyPersonTest, IsDesignTimeCreatable=False}"
xaml代码参考:
bash
在 XAML 中配置视图模型,通过 d:DataContext设置设计时类型(推荐)
在 XAML 中配置视图模型,通过 d:DataContext设置设计时类型(推荐)
<Window x:Class="WpfSnqkGasAnalysis.View.MyPersonTest"
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:local="clr-namespace:WpfSnqkGasAnalysis.View"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MyPersonTest, IsDesignTimeCreatable=False}"
d:DesignHeight="450" d:DesignWidth="800"
Title="测试">
</Window>
后台代码
csharp
namespace WpfSnqkGasAnalysis.View
{
/// <summary>
/// MyPersonTest.xaml 的交互逻辑
/// </summary>
public partial class MyPersonTest : Window
{
public MyPersonTest()
{
InitializeComponent();
this.DataContext = this;
}