4

有没有办法通过 s 确定 aToggleButton是否已检查/未检查DelegateCommand

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>
4

2 回答 2

7

一个更简单的解决方案是将IsChecked属性绑定到 ViewModel 的属性。这样你只需要检查财产价值......

于 2009-11-22T03:03:31.543 回答
1

您能否在 XAML 中以声明方式指定 CommandParameter 并使用元素绑定来使用切换的当前值填充该值?

于 2009-11-22T02:45:45.090 回答