2021年1月5日星期二

wpf image in toggle button doesn't show

I'm trying to make a toggle button style that allows the toggle button to show 2 different images when checked/unchecked. In the design preview I can see the Image in the toggle button, but in runtime the image doesn't show at all. I've been using resource as build action and copying to output directory but it doesn't help. Here is the code:

    <Window.Resources>          <Image Source="Images/pencil.png" x:Key="PencilImage"></Image>          <Image Source="Images/eraser.png" x:Key="EraserImage"></Image>            <Style TargetType="{x:Type ToggleButton}"           x:Key="ImageButton">              <Setter Property="Background" Value="Transparent"></Setter>              <Setter Property="Content"              Value="{DynamicResource PencilImage}" />              <Style.Triggers>                  <Trigger Property="IsChecked" Value="True">                      <Setter Property="Content" Value="{DynamicResource EraserImage}"/>                  </Trigger>                  <Trigger Property="IsChecked" Value="False">                      <Setter Property="Content" Value="{DynamicResource PencilImage}"/>                  </Trigger>              </Style.Triggers>          </Style>      </Window.Resources>    ...                    <Border Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="2" Height="25" Width="25">                      <ToggleButton Style="{StaticResource ImageButton}" Height="25" Width="25"/>                  </Border>  
https://stackoverflow.com/questions/65584885/wpf-image-in-toggle-button-doesnt-show January 06, 2021 at 02:54AM

没有评论:

发表评论