Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change button content when clicked in Xaml?

Tags:

c#

xaml

I have buttoncontent named Hold button. Once when I clicked button the button content should change to Resume, again if pressed resume button means Hold should be visible.

XAML code:

 <Button Style="{StaticResource CommonButtonStyle}" Template="{DynamicResource GlassButton}" ToolTip="F9" Click="Hold_Click" PreviewKeyDown="Hold_PreviewKeyDown" Name="OK" Margin="1,49,25,0" Grid.Column="2" Grid.Row="13" Grid.RowSpan="2">
        <StackPanel Style="{StaticResource ButtonStackPanel}">
            <Image Style="{StaticResource CancelImages}" />
            <TextBlock Text="{Loc lblHold}" Style="{StaticResource ButtonTextBlock}" />
        </StackPanel>
  </Button>
like image 313
mohamed farook Avatar asked Jul 09 '13 05:07

mohamed farook


1 Answers

You can try something like this in the button's Click event:

private void holdResumeButton_Click(object sender, RoutedEventArgs e)
{
        if ((string)holdResumeButton.Content == "Hold")
            holdResumeButton.Content = "Resume";

        else
            holdResumeButton.Content = "Hold";

}

XAML:

<Button x:Name="holdResumeButton" 
        Content="Hold"
        Click="holdResumeButton_Click"/>
like image 65
pcnThird Avatar answered Sep 25 '22 12:09

pcnThird