Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Change text in a button
posted

Hi

In my Grid I have dynamicly added columns that in some cases have child columns. In the parent column's Label there is a button that sets the  visibility of it's child columns.

My problem is that I want to change the content of the button when it's clicked. When the children are collapesed the button's content should be ">>" and when they are visible it should be "<<".

I tried to make a new button class and add a dependency property "IsExtended" and set the content in a style. But this only works on a button thats not in the grid.

Can someone tell me what I'm doing wrong?

/Sara

<Style x:Key="HeaderShowChildren" TargetType="{x:Type igDP:LabelPresenter}" BasedOn="{StaticResource DefaultLabelStyle}">

<Setter Property="ContentTemplate" >

<Setter.Value>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<TextBlock VerticalAlignment="Top" Height="80" Width="60" TextWrapping="Wrap" Margin="5,0,0,0" TextTrimming="CharacterEllipsis" Text="{Binding Content,RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource TextBlockToolTip}"/>

<Canvas VerticalAlignment="Top">

<Recipients:ExtendedButton Tag="{Binding RelativeSource={RelativeSource TemplatedParent}}" Click="ExtendedButton_Click" Margin="2" FontSize="8" Width="20" Height="15" Style="{StaticResource ExtendedButtonStyle}"/>

</Canvas>

</StackPanel>

</DataTemplate>

</Setter.Value>

</Setter>

</Style>

 

 

<Style x:Key="ExtendedButtonStyle" TargetType="{x:Type ExtendedButton }">

<Style.Triggers>

<Trigger Property="IsExtended" Value="true">

<Setter Property="Content" Value="&lt;&lt;"/>

</Trigger>

<Trigger Property="IsExtended" Value="false">

<Setter Property="Content" Value=">>"/>

</Trigger>

</Style.Triggers>

</Style>

 

private void ExtendedButton_Click(object sender, RoutedEventArgs e)

{

ChangeButtonContent((ExtendedButton)sender);

}

private void ChangeButtonContent(ExtendedButton button)

{

button.IsExtended = !button.IsExtended;

}

public class ExtendedButton: Button

{

public static readonly DependencyProperty IsExtendedProperty = DependencyProperty.Register("IsExtended", typeof (bool),

typeof (ExtendedButton));

public bool IsExtended

{

get { return (bool) GetValue(IsExtendedProperty); }

set

{

SetValue(IsExtendedProperty, value);

}

}

Parents Reply Children