开发者

WPF Changing text in a controltemplate at run time

I am making a template control so that I can have a button with an image that changes when you click it. I also am trying to get text on to开发者_开发百科p of the button that can change at run time. I have the button images and everything working but I can't seem to get that label at runtime so I can change the text. Here is the code in the xaml. I am missing the code behind

<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"/>


Difficult to decipher your question, but I think you just need to change the Label to a ContentControl and bind its Content property to the Button's Content property:

<ContentControl Content="{TemplateBinding Content}" .../>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜