Use DataGrid instead of ListView to improve performance when there's too many tags

This commit is contained in:
leo 2020-07-14 10:26:54 +08:00
parent 3f2624dfb8
commit c72e21d660
2 changed files with 40 additions and 27 deletions

View file

@ -369,29 +369,41 @@
</Button> </Button>
</Grid> </Grid>
</ToggleButton> </ToggleButton>
<ListView <DataGrid
Grid.Row="7" Grid.Row="7"
x:Name="tagList" x:Name="tagList"
Visibility="{Binding ElementName=tagListToggle, Path=IsChecked, Converter={StaticResource Bool2Collapsed}}" Visibility="{Binding ElementName=tagListToggle, Path=IsChecked, Converter={StaticResource Bool2Collapsed}}"
Background="{StaticResource Brush.BG3}" Background="{StaticResource Brush.BG3}"
RowHeight="24"
Height="200" Height="200"
LostFocus="TagLostFocus" LostFocus="TagLostFocus"
SelectionChanged="TagSelectionChanged" SelectionChanged="TagSelectionChanged"
ContextMenuOpening="TagContextMenuOpening" ContextMenuOpening="TagContextMenuOpening"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
Style="{StaticResource Style.ListView.Borderless}"> SelectionMode="Single"
<ListView.ItemTemplate> SelectionUnit="FullRow">
<DataTemplate DataType="{x:Type git:Tag}"> <DataGrid.Resources>
<Grid Margin="16, 0, 0, 0" Height="20"> <Style x:Key="Style.DataGridText.TagName" TargetType="{x:Type TextBlock}">
<Grid.ColumnDefinitions> <Setter Property="VerticalAlignment" Value="Center"/>
<ColumnDefinition Width="16"/> <Setter Property="Foreground" Value="{StaticResource Brush.FG}"/>
<ColumnDefinition Width="*"/> </Style>
<ColumnDefinition Width="Auto"/> </DataGrid.Resources>
</Grid.ColumnDefinitions>
<Path Grid.Column="0" Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Tag}"/> <DataGrid.Columns>
<Label Grid.Column="1" Margin="4,0,0,0" Content="{Binding Name}" Padding="4,0,0,0"/> <DataGridTemplateColumn Width="26">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Path Width="10" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Tag}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Width="*" IsReadOnly="True" Binding="{Binding Name}" ElementStyle="{StaticResource Style.DataGridText.TagName}"/>
<DataGridTemplateColumn Width="16">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ToggleButton <ToggleButton
Grid.Column="2" Grid.Column="2"
IsChecked="{Binding IsFiltered, Mode=TwoWay}" IsChecked="{Binding IsFiltered, Mode=TwoWay}"
@ -399,10 +411,11 @@
Unchecked="FilterChanged" Unchecked="FilterChanged"
Style="{StaticResource Style.ToggleButton.Filter}" Style="{StaticResource Style.ToggleButton.Filter}"
ToolTip="FILTER"/> ToolTip="FILTER"/>
</Grid>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </DataGridTemplateColumn.CellTemplate>
</ListView> </DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid> </Grid>
<!-- Splitter --> <!-- Splitter -->

View file

@ -838,7 +838,7 @@ namespace SourceGit.UI {
} }
private void TagLostFocus(object sender, RoutedEventArgs e) { private void TagLostFocus(object sender, RoutedEventArgs e) {
(sender as ListView).UnselectAll(); (sender as DataGrid).UnselectAll();
} }
private void TagSelectionChanged(object sender, SelectionChangedEventArgs e) { private void TagSelectionChanged(object sender, SelectionChangedEventArgs e) {
@ -849,7 +849,7 @@ namespace SourceGit.UI {
} }
private void TagContextMenuOpening(object sender, ContextMenuEventArgs e) { private void TagContextMenuOpening(object sender, ContextMenuEventArgs e) {
var tag = (sender as ListView).SelectedItem as Git.Tag; var tag = (sender as DataGrid).SelectedItem as Git.Tag;
if (tag == null) return; if (tag == null) return;
var createBranch = new MenuItem(); var createBranch = new MenuItem();