单击gridview列标题整个gridview尝试覆盖窗口

时间:2012-03-06 17:23:52

标签: c# .net wpf xaml gridview

我通过单击列标题对GridView进行排序。但是,当我向gridview添加更多项目并且它变为可滚动时,第一次单击列标题不会对项目进行排序。相反,它向上移动gridview并尝试显示可用空间中的所有项目。

是否有一些属性我必须设置以防止这种情况?这是GridView的代码:

<Window x:Class="AutomatedExitStrategy.Presentation.View.AutomatedExitStrategyShell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Automated Exit Strategy System" Height="480" 
    Width="2125">

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Grid Opacity="1">
    <Grid.RowDefinitions>
        <RowDefinition Height="0.20*"/>
        <RowDefinition Height="0.80*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"/>
        </Grid.ColumnDefinitions>
        <ListView
            Grid.Row="1" 
            Margin="0,2,0,0" 
            IsSynchronizedWithCurrentItem="True" 
            ItemsSource="{Binding GlobalRowsCollection}"
            AlternationCount="2">
            <ListView.View>
                <GridView>
                    <GridViewColumn
                        Width="25">
                        <GridViewColumnHeader Command="{Binding SortList}" CommandParameter="IsEnabled"></GridViewColumnHeader>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox Margin="0"
                                          VerticalAlignment="Center"
                                          HorizontalAlignment="Left"
                                          IsChecked="{Binding IsChecked}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn 
                        Width="Auto">
                        <GridViewColumnHeader Command="{Binding SortList}" CommandParameter="InputViewModel.Group">Grp</GridViewColumnHeader>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Text="{Binding InputViewModel.Group}" 
                                               Style="{StaticResource GridBlockStyle}"
                                               HorizontalAlignment="Center"/>
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>

1 个答案:

答案 0 :(得分:0)

您应该订阅ListView的RequestBringIntoView事件并将其标记为已处理。

这应该会阻止ScrollViewer向下滚动以在单击时尝试显示整个ListView。因此,它应该允许MouseDown事件继续运行并触发排序。

<ListView Grid.Row="1" 
          Margin="0,2,0,0" 
          IsSynchronizedWithCurrentItem="True" 
          ItemsSource="{Binding GlobalRowsCollection}"
          AlternationCount="2"
          RequestBringIntoView="ListView_RequestBringIntoView">
    ...
</ListView>

关于代码隐藏......

public void ListView_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
    e.Handled = true;
}