我尝试使用绑定到IsChecked属性为2 togglebuttons创建简单逻辑,并使用DataTriggers在第二个ToggleButton中捕获绑定值chnaging,如下所示:
<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>
当第二个Togglebutton未选中时,第一个按钮也必须取消选中,但据我所知,虽然第一个按钮的IsChecked属性设置为false,但属性CameraAcceleration.Config.UI.IsSyncMovementXYZActivated未被设置为false,因此,当我取消选中第二个按钮时,第一个再次被检查。 预期结果:第一个按钮必须保持未选中状态。
我在这里做错了什么?
答案 0 :(得分:0)
<DataTrigger Binding="{Binding Path=CameraAcceleration.Config.UI.IsSyncMovementXYActivated, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="True">
此行可能是错误。将Mode=OneWay
更改为Mode=TwoWay
。
为了在与View交互时更新属性,模式始终设置为TwoWay
。