切换按钮 - 单击时更改图标

Toggle button - change icon on click

我有一个 WPF 应用程序。我正在使用 entypo 图标,我将其中一个贴标为资源:

<Grid.Resources>
  <iconPacks:Entypo x:Key="PlayIcon" Width="50" Height="30" Kind="ControllerPlay"></iconPacks:Entypo>                              
</Grid.Resources>

假设我有两个这样的图标(play/pause 图标),我想在用户单击 ToggleButton 时在它们之间切换。我想到了这样的方法,但不幸的是,它不起作用:

<ToggleButton>
   <Image>
      <Image.Style>
          <Style TargetType="{x:Type Image}">
             <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}"
                 Value="true">
                    <Setter Property="Source"
                     Value="{StaticResource PauseIcon}" />
                 </DataTrigger>
                 <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}"
                  Value="false">
                     <Setter Property="Source"
                      Value="{StaticResource PlayIcon}" />
                 </DataTrigger>
              </Style.Triggers>
            </Style>
       </Image.Style>
   </Image>
</ToggleButton>

谁能告诉我是否可以像这样实现(稍作修改)或指出正确的方向?

您不能将 ImageSource 设置为 PackIconEntypo。将 ToggleButtonContent 属性 设置为:

<ToggleButton>
    <ToggleButton.Style>
        <Style TargetType="{x:Type ToggleButton}">
            <Setter Property="Content" Value="{StaticResource PlayIcon}" />
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Content" Value="{StaticResource PauseIcon}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ToggleButton.Style>
</ToggleButton>