当前位置:网站首页>UWP WPF 解决 xaml 设计显示异常
UWP WPF 解决 xaml 设计显示异常
2022-08-04 15:38:00 【林德熙】
本文告诉大家如何解决 xaml 设计显示异常
虽然垃圾微软可以在写的时候直接让开发者看到界面,但是他的设计比较烂,总是无法使用
或者
简单的方法是禁用项目代码,在左下角可以找到这个按钮 禁用代码
另一个方法是设置判断当前是否在设计,如果是就直接返回,一般写在构造函数
WPF
例如我创建一个用户控件 TsjcyubtnTtqtjem 那么就可以在构造函数添加下面代码
public TsjcyubtnTtqtjem()
{
InitializeComponent();
if (DesignerProperties.GetIsInDesignMode(this))
{
return;
}
foreach (var temp in typeof(Brushes)
.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
.Select(temp => temp.GetValue(null, null)))
{
var rectangle = new Rectangle
{
Height = 20,
Fill = (Brush)temp
};
HcrkKmqnnfzo.Children.Add(rectangle);
}
}
上面代码实际使用 DesignerProperties.GetIsInDesignMode
判断当前是否设计,如果是就返回,然后关闭这个类再打开一般就可以继续写的时候获得界面。
UWP
在 UWP 可以通过Windows.ApplicationModel.DesignMode.DesignModeEnabled
判断,或者通过DesignMode.DesignMode2Enabled
判断,因为 DesignMode2Enabled 需要秋季更新以上的才可以使用。
public AssBjPage()
{
this.InitializeComponent();
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
return;
}
}
上面的代码需要在所有的引用控件加上,一般的微软控件不需要,因为他里面有加上
边栏推荐
猜你喜欢
攻防视角下,初创企业安全实战经验分享
在Markdown文件中快速插入本地图片
JVM Tuning-GC Fundamentals and Tuning Key Analysis
Projector reached the party benefits 】 【 beginners entry - brightness projection and curtain selection - from entry to the master
Taurus.MVC WebAPI 入门开发教程2:添加控制器输出Hello World。
RTC 场景下的屏幕共享优化实践
74行代码实现浪漫的红心下落的动画效果
C端折戟,转战B端,联想的元宇宙梦能成吗?
GPS satellite synchronization clock, NTP network synchronization clock, Beidou clock server (Jingzhun)
分支控制if-else
随机推荐
Byte、Short、Integer、Long内部缓存类的对比与源码分析
【Es6中的promise】
ICDE‘22推荐系统论文之Research篇
农产品期货开户哪家好??
#夏日挑战赛# HarmonyOS 实现一个滑块验证
附加:自定义注解(参数校验注解);(写的不好,别看…)
What are the useful IT asset management platforms?
录音文件识别
推荐一个鸿蒙即时通讯软件《果聊》
What is the difference between member variable and local variable
第三章 Scala运算符
直播回放含 PPT 下载|基于 Flink & DeepRec 构建 Online Deep Learning
Legal education combined with VR panorama, intuitively feel and learn the spirit of the rule of law
成功 解决 @keyup.enter=“search()“ 在el-input 组件中不生效的问题
Many merchants mall system function and dismantling 24 - ping the strength distribution of members
Summary of some pytorch knowledge points that have been updated for a long time
numpy入门详细代码
365天挑战LeetCode1000题——Day 049 非递增顺序的最小子序列 贪心
李沐的深度学习笔记来了!
洛谷题解P1028 数的计算