WPF列表框与复选框多检查

WPF列表框与复选框多检查

本文介绍了WPF列表框与复选框多检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF列表框与添加到它的复选框,并在那一刻,它看起来是这样的:

I've got a WPF listbox with checkboxes added to it, and at the moment it looks like this:

要选择所有不同的项目我一定要单击每个复选框,一个接一个,或做全选(我有一个单独的按钮)。但是,如果我要选择只有一半的话,那是痛苦的。

To select all the different items I have to click each checkbox one by one, or do a select all (which I have a separate button for). But if I want to select only half, then it is painful.

我希望能够做的就是单击其中一个,按住shift,单击其他,然后点击旁边的复选框,其中一个切换所有的这些选择。 Windows窗体允许,pretty的容易我想,但我不知道该怎么做在WPF?目前,我已经把它设置为只允许选择一个在时间(选择意味着什么,它的所有关于检查)。

What I'd like to be able to do is click one, hold shift, click another and then click the checkbox next to one of them to toggle all those selected. Windows Forms allows this pretty easily I think, but I'm not sure what to do in WPF? At the moment I've got it set to only allow selecting of one at a time (selection means nothing, its all about the checks).

在理想情况下我也有这么选择的东西会检查它(即,而不必挑选出的小框,您可以点击的话),但我认为这可能是很难做到与我的SHIFT +选择的事情。

Ideally I'd also have it so selecting something checks it (ie instead of having to pick out the small checkbox you can click the words) but I think that may be hard to do with my shift+select thing.

    <Window.Resources>
    <DataTemplate x:Key="ListBoxItemTemplate" >

        <WrapPanel>
            <CheckBox Focusable="False" IsChecked="{Binding Selected}" VerticalAlignment="Center" />
            <ContentPresenter Content="{Binding Name, Mode=OneTime}"  Margin="2,0" />
        </WrapPanel>

    </DataTemplate>

</Window.Resources>

<ListBox Margin="10" HorizontalAlignment="Stretch" Name="lbSheets"
                 VerticalAlignment="Stretch" Width="Auto" Grid.Row="1" MinWidth="321"
                 MinHeight="40" HorizontalContentAlignment="Left"
                 ItemTemplate="{StaticResource ListBoxItemTemplate}" VerticalContentAlignment="Top" Background="#FFDCEBEE" SelectionMode="Single">

</ListBox>

我希望这一切是有道理的 - 什么是做这在WPF的最好办法

I hope this all makes sense - what is the best way to do this in WPF?

推荐答案

查看SelectionMode属性。请注意,当在扩展模式下,你可以按住Shift键单击项目组,通过点击在ListBoxItem中的文本或CheckBox.Read下面的文章,你会得到一个更好的主意。

Check out the SelectionMode Property. Notice that when in Extended mode, you can Shift-Click groups of items, by clicking over the ListBoxItem text or CheckBox.Read the below article and you will get a better idea

HTTP://www.$c$cproject.com/KB/ WPF / WPFProblemSolving.aspx

这篇关于WPF列表框与复选框多检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:08