【发布时间】:2012-05-29 05:02:57
【问题描述】:
我正在尝试为我可以在表单上反复使用的按钮创建一个模板。
Button,我希望它包含一个有两行的Grid,并在底行中包含一段自定义文本。
这是我到目前为止所得到的,但我认为它不正确,因为我想从按钮元素中设置文本。
<ControlTemplate TargetType="Control">
<Grid Width="444">
<Grid.RowDefinitions>
<RowDefinition Height="51" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#286c97"></Grid>
<Grid Grid.Row="1" Background="#5898c0">
<TextBlock Grid.Row="1" FontFamily="Segoe UI" FontSize="12" Text="{TemplateBinding Content}" />
</Grid>
</Grid>
</ControlTemplate>
然后调用我希望我可以去的模板:
<Button Content="This is the text" />
但遗憾的是,这不起作用。我应该使用其他模板将文本值传递给它吗?
【问题讨论】:
标签: c# wpf templates button text