0

Is the any way to make Checked and Unchecked only fire when button clicked by user?

IsChecked is bound to Playing property. This value may change from background (not by user). So it causes Checked and Unchecked events to fire again and conflict with other things.

When ever I try to write code to fix this it becomes real mess. Thanks for your help.

<ToggleButton x:Name="TogglePlay" Width="90"
              Style="{DynamicResource TogglePlay}" 
              IsChecked="{Binding SessionData.Playing}"
              Checked="TogglePlay_Checked" Unchecked="TogglePlay_OnUnchecked"/>
<StackPanel.Resources>
    <Style x:Key="TogglePlay" TargetType="ToggleButton">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsChecked , ElementName=TogglePlay}" Value="False">
                <Setter Property="Content" Value="Play" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsChecked , ElementName=TogglePlay}" Value="True">
                <Setter Property="Content" Value="Pause" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</StackPanel.Resources>
ivayle
  • 1,070
  • 10
  • 17
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118

1 Answers1

1

You can try to use binding mode "OneWayToSource"

acidhills
  • 36
  • 1
  • 2