且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将combobx的selectedindex绑定到togglebutton C#

更新时间:2022-06-19 08:28:37

然后在ToggleButton上为Combobox命名:
give the Combobox a name then on the ToggleButton:
<ToggleButton Content={Binding ElementName=ComboBoxName, Path=SelectedIndex}"/>

或任何需要绑定的属性。

or to whatever property that needs binding.


感谢您的快速回复。这是我的Togglebutton目前的样子。我已经将它绑定到了某个东西,所以可以将它绑定到其他东西吗?





< ToggleButton x:Name =btnPlayersTemplate ={StaticResource ctpDetailButton}Horizo​​ntalContentAlignment =CenterVerticalContentAlignment =CenterCommand ={Binding SelectedCommand, Mode = TwoWay}IsChecked ={绑定IsChecked,M ode = TwoWay,UpdateSourceTrigger = Explicit}>



**你可以忽略其他属性。另一件事,组合框在MainWindow.xaml中的另一个UserControl中 -
Thanks for the prompt reply. Here is what my Togglebutton looks like currently. I am already binding it to something, so is it possible to bind it to something else?


<ToggleButton x:Name="btnPlayers" Template="{StaticResource ctpDetailButton}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Command="{Binding SelectedCommand, Mode=TwoWay}" IsChecked="{Binding IsChecked,Mode=TwoWay,UpdateSourceTrigger=Explicit}" >

**you can ignore other properties here. Another thing, the combobox is in a different UserControl -it's in the MainWindow.xaml