0

我是 WPF 新手。我在 WPF 的列表视图中有一个复选框列表。我有功能,当用户单击复选框时,它会突出显示该行。一切正常。但是,当复选框被禁用时,它仍然会突出显示该行并且它还会检查复选框。我如何使它不突出显示或检查用户何时单击禁用的复选框?提前致谢。

<ListView ScrollViewer.ScrollChanged="lstRewardsExpiration_ScrollChanged" Height="178" HorizontalAlignment="Left" Margin="12,0,0,81" Name="lstRewardsEarned" VerticalAlignment="Bottom" Width="327" SelectionMode="Multiple" Background="White" FontFamily="Calibri" FontSize="16">
    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}" />

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border x:Name="Border" SnapsToDevicePixels="true">
                            <ContentPresenter />
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="Border" Property="Background" Value="Cyan"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="False">
                                <Setter TargetName="Border" Property="Background" Value="Transparent"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>
4

1 回答 1

1

您可能必须使用 aMultiTrigger才能使其正常工作

如果我正确阅读了您的问题,这是一个示例

 <Style TargetType="{x:Type ListViewItem}">
    <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}" />

    <!-- bind content IsEnabled to the ListViewItem IsEnabled -->
    <Setter Property="IsEnabled" Value="{Binding Path=IsEnabled, Mode=TwoWay}" />

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Border x:Name="Border" SnapsToDevicePixels="true">
                    <ContentPresenter />
                </Border>

                <ControlTemplate.Triggers>

                    <!--Highlight if IsSelected and IsEnabled-->
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsSelected" Value="True"/>
                            <Condition Property="IsEnabled" Value="True"/>
                        </MultiTrigger.Conditions>
                        <MultiTrigger.Setters>
                            <Setter TargetName="Border" Property="Background" Value="Cyan"/>
                        </MultiTrigger.Setters>
                    </MultiTrigger>

                    <!--Remove highlight if is not Selected and IsEnabled-->
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsSelected" Value="False"/>
                            <Condition Property="IsEnabled" Value="True"/>
                        </MultiTrigger.Conditions>
                        <MultiTrigger.Setters>
                            <Setter TargetName="Border" Property="Background" Value="Transparent"/>
                        </MultiTrigger.Setters>
                    </MultiTrigger>

                    <!--Add a trigger to remove the higlighting if IsEnabled is changed to false-->
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="Border" Property="Background" Value="Transparent"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2013-03-12T21:22:50.663 回答