0

There are basically two things I am trying to activate or implement:

1. Clearing selection when background is clicked:

Typically, when one clicks in a blank area of a list view type control, such as windows explorer, any selected items become unselected. This is not happening for me in either multiple or extended selection mode. Do I have to manually handle the mouse click event to clear the selection, or is it perhaps not behaving as expected because I've applied a background to the control?

2. Selection rectangle with automatic scrolling:

Before porting my application to WPF, the standard WinForms listview allowed me to drag a selection rectangle and it would select any items it intersected. If there were items scrolled out of view in any direction, dragging in that direction would result in the control automatically scrolling into that area as I dragged the mouse, so I could selected items that are out of view. Does the WPF ListView implement this feature, or am I going to have to implement it myself? Someone posted a non-trivial implementation involving hittests in the comments on this page (http://social.msdn.microsoft.com/Forums/vstudio/en-US/191af722-e32b-4e6d-a00b-9ad2b53ea3b9/listview-dragging-a-selection-box-around-items?forum=wpf), but it doesn't even support the autoscrolling and I'm having a hard time believing Microsoft just left this feature out.

4

1 回答 1

-2

真的 ListView 没有默认外观,您甚至必须使用触发器设置基本选择。
哇,这会在没有单一样式或触发器的情况下着色并显示 SelectedIndex。
全部在 XAML 中

<Window.Resources>
    <sys:String x:Key="MyString">Hello</sys:String>
    <x:Array x:Key="MyStringArray" Type="sys:String">
        <sys:String>Hello</sys:String>
        <sys:String>World</sys:String>
        <sys:String>Continent</sys:String>
        <sys:String>Universe</sys:String>
    </x:Array>
</Window.Resources>
<Grid>
    <StackPanel Orientation="Vertical">
        <ListView ItemsSource="{StaticResource MyStringArray}" x:Name="lv" SelectionMode="Single"  LostFocus="lv_LostFocus">
        </ListView>
        <TextBlock Text="{Binding ElementName=lv, Path=SelectedIndex}" />
        <Button Content="Take Focus"/>
    </StackPanel>
</Grid>

    private void lv_LostFocus(object sender, RoutedEventArgs e)
    {
        lv.SelectedIndex = -1;
    }
于 2014-02-12T22:10:04.700 回答