0
votes

I try to make simple logic for 2 togglebuttons using binding to IsChecked property and DataTriggers for catching binded value chnaging in second ToggleButton like this:

<ToggleButton 
    ToolTip="{Binding Source={StaticResource CameraLocalization}, Path=ToolTips.SyncMovementXYZ, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
    Tag="{Binding Path=CameraAcceleration, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
    <ToggleButton.Style>
        <Style TargetType="ToggleButton" BasedOn="{StaticResource CameraSyncLastSectionStyle}">
                    <Setter Property="IsChecked" Value="{Binding Path=Property1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></Setter>
            <Setter Property="Content" Value="{DynamicResource PinIcon}"></Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Property2, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="True">
                    <Setter Property="IsChecked" Value="False"></Setter>
                </DataTrigger>
                <Trigger Property="IsChecked" Value="False">
                    <Setter Property="Content" Value="{DynamicResource UnpinIcon}"></Setter>
                </Trigger>
                </Style.Triggers>
        </Style>
    </ToggleButton.Style>
</ToggleButton>
<ToggleButton
    ToolTip="{Binding Source={StaticResource CameraLocalization}, Path=ToolTips.SyncMovementXY, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
    Tag="{Binding Path=CameraAcceleration, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
    <ToggleButton.Style>
        <Style TargetType="ToggleButton" BasedOn="{StaticResource CameraSyncAdditionalStyle}">
            <Setter Property="IsChecked" Value="{Binding Path=Property2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></Setter>
            <Setter Property="Content" Value="{DynamicResource PinIcon}"></Setter>
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="False">
                    <Setter Property="Content" Value="{DynamicResource UnpinIcon}"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ToggleButton.Style>
</ToggleButton>

When 2nd Togglebutton unchecked, 1st button must also be unchecked, but as far as I see, property CameraAcceleration.Config.UI.IsSyncMovementXYZActivated not being set to false although IsChecked property of 1st button was set to false and because of this, when I uncheck 2nd button, 1st become checked again. Expected result: 1st button must stays unchecked.

What I am doing wrong here?

1
Post your code behind the XAML markup. You actually don't need any triggers, a two-way binding to both ToggleButtons should do the trick.0x8BADF00D
A have no codebehind for this XAML. I do need triggers at least to change buttons content depending on its state. Also I need binding to my properties like: Path=CameraAcceleration.Config.UI.IsSyncMovementXYZActivated, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged to know current stateDenis
Are you using the MVVM pattern? If so, you could represent the state as boolean and bind the property to both ToggleButtons. If something set the boolean property, both ToggleButtons are changing it's state. I could write a detailed answer if that is, what you want.0x8BADF00D
The trick is that these 2 buttons need to be binded to different properties. The only thing I want to do - I described in my first post - nothing more. Is it possible to rich this using only XAML?Denis

1 Answers

0
votes
<DataTrigger Binding="{Binding Path=CameraAcceleration.Config.UI.IsSyncMovementXYActivated, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="True">

This line might be the error. Change Mode=OneWay to Mode=TwoWay.

In order to update the property while interacting with the View, the mode has always to be set to TwoWay.