Forsaiken
Forsaiken

Reputation: 344

How to change property of a button content with trigger

I need to know how to change a content property inside the triggers of the control.

I have a piece of code, that is actually working, but instead of replace the icon, I want to change the Foreground of the content (icon)

<ToggleButton x:Name="btEditar" Width="30" Height="26" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Margin="344,19,0,0" Click="btEditar_Click" IsEnabled="False" >
  <ToggleButton.Style>
    <Style TargetType="{x:Type ToggleButton}">
      <Setter Property="Content">
        <Setter.Value>
           <iconPacks:PackIconModern Kind="PageEdit" Foreground="Black" Background="#00FFFFFF" Height="20" Width="20" VerticalAlignment="Center" IsEnabled="False"/>
        </Setter.Value>
      </Setter>
      <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
          <Setter Property="Content">
            <Setter.Value>
              <iconPacks:PackIconModern Kind="PageEdit" Foreground="Gray" Background="#00FFFFFF" Height="20" Width="20" VerticalAlignment="Center" IsEnabled="False"/>
            </Setter.Value>
          </Setter>
        </Trigger>
      </Style.Triggers>
    </Style>
  </ToggleButton.Style>
</ToggleButton>

How can I do that?

Upvotes: 1

Views: 788

Answers (1)

Keithernet
Keithernet

Reputation: 2509

This should do the trick:

<ToggleButton x:Name="btEditar"
    Grid.Row="1"
    Width="30"
    Height="26"
    Margin="344,19,0,0"
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    Click="btEditar_Click"
    IsEnabled="False">
    <ToggleButton.Style>
        <Style TargetType="{x:Type ToggleButton}">
            <Setter Property="Foreground" Value="Black" />
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="Gray" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ToggleButton.Style>
    <iconPacks:PackIconModern 
        Kind="PageEdit" 
        Background="#00FFFFFF" 
        Height="20" 
        Width="20" 
        VerticalAlignment="Center" 
        IsEnabled="False"/>
</ToggleButton>

Upvotes: 2

Related Questions