我正在制作模板控件,以便我可以使用一个按钮,其中的图像在您单击时会发生变化。我也试图在按钮的顶部获取文本,可以在运行时更改。我有按钮图像和一切正常但我似乎无法在运行时获得该标签,所以我可以更改文本。这是xaml中的代码。我错过了
背后的代码<UserControl.Resources>
<ControlTemplate TargetType="{x:Type Button}" x:Key="ActionButton">
<Grid>
<Label Panel.ZIndex="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Arial" Name="lblText" Foreground="#5E4421" FontWeight="Bold" FontSize="14">Test</Label>
<Image Name="Normal" Source="/AssaultWare.Controls;component/Replayer/Images/button_off.png"/>
<Image Name="Pressed" Source="/AssaultWare.Controls;component/Replayer/Images/button_on.png"/>
<Image Name="Disabled" Source="/AssaultWare.Controls;component/Replayer/Images/button_off.png" Visibility="Hidden"/>
</Grid>
<ControlTemplate.Triggers>
...
</ControlTemplate.Triggers>
</ControlTemplate>
</UserControl.Resources>
<Button Canvas.Left="471" Canvas.Top="465" Template="{StaticResource ActionButton}" Name="btnRight"/>
答案 0 :(得分:2)
难以破译您的问题,但我认为您只需将Label
更改为ContentControl
并将其Content
属性绑定到Button
的{{1}} 1}} property:
Content