WPF ToggleButton和DelegateCommand

Mik*_*ike 4 wpf commandbinding delegatecommand togglebutton

有没有办法确定是否ToggleButton通过DelegateCommands 检查/取消检查?

TIA,迈克

下面的XAML代码.我正在使用ItemsControl并绑定到一个集合.我基本上想要一种方法来获得每个按钮点击时的切换状态.

<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>
Run Code Online (Sandbox Code Playgroud)

Tho*_*que 7

更简单的解决方案是将IsChecked属性绑定到ViewModel的属性.那样你只需检查属性值......