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.
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"/>
Maybe you can use ToggleButton
instead of Button
so you can bind to IsChecked
property.
http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.ischecked.aspx
For example:
<ToggleButton x:Name="TB">
<ToggleButton.Style>
<Style>
<Style.Triggers>
<Trigger Property="ToggleButton.IsChecked" Value="True">
<Setter Property="ToggleButton.Content" Value="Resume"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
Use ToggleButton
:
<Style x:Key="HoldOrResumeButton" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="Content">
<Setter.Value>
<TextBlock Text="Hold"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource Mode=Self}}" Value="True">
<Setter Property="Content">
<Setter.Value>
<TextBlock Text="Resume"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>