【发布时间】:2011-05-16 01:52:02
【问题描述】:
我有一个继承自 Button 的类。在该类的 XAML 中,我指定了宽度和高度以及内容,希望当我使用 VS2010 WPF 设计器将我的控件插入到例如一个窗口,这些将是这些属性的默认值。但是,设计器使用 Button 的默认值。
我的控制 XAML:
<Button x:Class="Something.FunctionButton4"
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"
mc:Ignorable="d"
d:DesignHeight="64" d:DesignWidth="64"
Height="64" Width="64" Content="FunctionButton"
OverridesDefaultStyle="True"
Focusable="False">
<Button.Template>
<ControlTemplate TargetType="Button">
...
</ControlTemplate>
</Button.Template>
</Button>
设计器生成的 XAML:
<my:FunctionButton4 Content="Button" Height="23" x:Name="functionButton43" Width="75" />
我需要做什么来控制设计器默认值?
【问题讨论】:
-
@Craig,您链接到的问题似乎恰恰相反:它是关于 not 使用控件的宽度和高度(在运行时),而这个问题是关于 想要使用它们(在设计时)。
-
@Joe,原来如此。我误读了。应该适用相同的原则,但它可能仍然有用。
标签: wpf visual-studio-2010 controls designer