【发布时间】:2015-02-03 16:48:19
【问题描述】:
我正在尝试使用样式和 ControlTemplate 创建一个通用页面导航按钮。这个想法是目标页面是按钮的CommandParameter:
<Button Height="64" Width="64" Style="{DynamicResource ButtonViewTileStyle}"
Command="{Binding Path=ChangePage}"
CommandParameter="{Binding Path=HomePage}"/>
...每个页面都有一个 DisplayName 和 IconName 属性,我想在 ControlTemplate 中使用它们。这是一个仅显示名称的无效示例:
<Style x:Key="ButtonViewTileStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Canvas>
<TextBlock TextWrapping="Wrap"
Text="{Binding CommandParameter.DisplayName,
RelativeSource={RelativeSource TemplatedParent}}"
Canvas.Left="0" Canvas.Top="0"
HorizontalAlignment="Center" VerticalAlignment="Center"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"/>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
关于 Text= 绑定应该如何实现这项工作的任何建议?
【问题讨论】:
标签: wpf wpf-controls data-binding