WPF ToggleButton and DelegateCommand

Is there a way to determine if ToggleButton checked or not checked using DelegateCommand s?

TIA, microphone

The XAML code is below. I use ItemsControl and bind to the collection. I basically want to get the switching status of each button when pressed.

 <ScrollViewer VerticalScrollBarVisibility="Auto"> <ItemsControl ItemsSource="{Binding Modifiers, Mode=TwoWay}"> <ItemsControl.Template> <ControlTemplate> <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto"> <WrapPanel Margin="10" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" FlowDirection="LeftToRight" IsItemsHost="true"> </WrapPanel> </ScrollViewer> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemTemplate> <DataTemplate> <ToggleButton FontSize="18" Opacity="0.8" Command="{Binding DataContext.ModifierToggleCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:ModifiersView}}}" CommandParameter="{Binding}" Height="80" Width="200" Margin="5" Content="{Binding Path=ModifierName}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> 
+4
source share
2 answers

A simpler solution would be to bind the IsChecked property to the property of your ViewModel. So you just need to check the value of the property ...

+7
source

Is it possible to describe CommandParameter declaratively in XAML and use element binding to populate the value with the current value of the switch?

+1
source

All Articles