创建仅适用于设计时的属性 [英] Create properties that only apply on design time
问题描述
我正在使用 Visual Studio 深色主题.因此,在设计我的视图时,如果它是黑色的,我就看不到字体.解决方法是将视图的背景设置为白色.但是我们的应用程序具有不同的主题,因此我无法对其进行硬编码.
I am using visual studio dark theme. As a result when designing my views I cannot see the font if its black. A fix will be to set the background of the view to white. But our application has different themes so I cannot hard code that.
我在创建用户控件时使用了很多很棒的属性:
There are to great properties that I use when creating an usercontrol:
d:DesignWidth="1110" d:DesignHeight="400"
这些属性只在设计时影响视图.如果我可以创建一个属性 d:DesignBackground
就太好了,这样我就不必在每次运行应用程序时添加和删除背景属性.
those properties are only affecting the view at design time. It will be great if I can create a property d:DesignBackground
just so that I do not have to be adding and removing the background property every time I run the application.
推荐答案
不确定这是否正是您要查找的内容,但我所做的只是在 app.xaml 中插入一个触发器以使用 进行调用IsInDesignMode
属性如;
Not sure if it's exactly what you're looking for, but what I do is just plop a trigger in the app.xaml to invoke using the IsInDesignMode
property like;
命名空间(感谢 Tono Nam);
Namespace (Thanks Tono Nam);
xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=PresentationFramework"
XAML;
<Style TargetType="{x:Type UserControl}">
<Style.Triggers>
<Trigger Property="ComponentModel:DesignerProperties.IsInDesignMode"
Value="True">
<Setter Property="Background"
Value="#FFFFFF" />
</Trigger>
</Style.Triggers>
</Style>
简单,但有效,有时我也根据需要定位其他依赖属性,如字体和东西.希望这会有所帮助.
Simple, but works, and sometimes I target other dependency properties like font and stuff too depending on the need. Hope this helps.
PS - 您可以以相同的方式定位其他具有自己属性的 TargetType,例如 ChildWindows、Popups、Windows 等等...
PS - You can target other TargetType's with their own properties the same way, like for example, ChildWindows, Popups, Windows, whatever...
这篇关于创建仅适用于设计时的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!