ToggleButton 支持 ICommand,所以我创建了许多命令,例如 TogglePlayPause、ToggleMute,它工作正常,但我也需要绑定 IsChecked 属性,所以它的检查状态总是显示正确的状态。但是当我为 ToggleButton 创建 OneWay 绑定模式并且当我按下 ToggleButton 时,绑定将丢失。
问题是为什么 ToggleButton 支持 ICommand 但不支持 OneWay 绑定?我可以设置 TwoWay 绑定,但 ToggleButton 使用 Command 时是个坏主意,因为 Command 处理的实际操作不应该与 TwoWay 绑定重复,有时也不可能。在我的情况下 Command=TogglePlayPause IsChecked={Bind to IsMediaPlaying} IsMediaPlaying 应该是只读的。
那么请告诉我如何将 ToggleButton 与 Command 一起使用并绑定其 IsChecked 属性?