且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建仅适用于设计时的属性

更新时间:2023-12-06 08:21:40

不确定这是否正是您要查找的内容,但我所做的只是在 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...