wpf 在XAML中配置视图模型,通过 d:DataContext设置设计时类型,方便按F12跳转查看类型

关键代码:

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;
 
        }
相关推荐
nap11719 小时前
WPF 中常用的 LINQ 语句
wpf
做个文艺程序员4 天前
MQ第12篇:AI原生消息架构演进:从MQ到事件驱动的全链路设计
架构·消息队列·wpf·事件驱动架构·ai-native·cqrs
donk13146 天前
React Native for OpenHarmony 实战:三方库 react-native-circular-action-menu 的鸿蒙化适配指南
javascript·分布式·react native·react.js·wpf·harmonyos
donk13147 天前
React Native for OpenHarmony 实战:三方库 react-native-step-indicator 的鸿蒙化适配指南
分布式·react native·react.js·wpf·harmonyos
He BianGu7 天前
【笔记】WPF中RenderOptions类的详细功能
笔记·wpf
VidDown7 天前
上线三个月后的第一次事故:一个 Django 服务的日志、监控与故障复盘
数据库·python·django·wpf·音视频·视频编解码
He BianGu7 天前
【笔记】WPF中CachingHint的功能
笔记·wpf
He BianGu7 天前
【笔记】在WPF中BitmapScalingMode的作用
笔记·wpf
Vae_Mars8 天前
幂等性学习笔记
笔记·学习·wpf