2012-03-06 11 views
4

Я сортирую GridView, щелкнув заголовок столбца. Однако, когда я добавляю больше элементов в 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> 

+0

могли бы вы предоставить код видовую и код окна (если таковой существует), поэтому проблема может быть проверена? –

ответ

0

Вы должны подписаться на RequestBringIntoView случае ListView и пометить его как обработанное.

Это должно предотвратить прокрутку 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; 
} 
Смежные вопросы