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

View file

@ -838,7 +838,7 @@ namespace SourceGit.UI {
}
private void TagLostFocus(object sender, RoutedEventArgs e) {
(sender as ListView).UnselectAll();
(sender as DataGrid).UnselectAll();
}
private void TagSelectionChanged(object sender, SelectionChangedEventArgs e) {
@ -849,7 +849,7 @@ namespace SourceGit.UI {
}
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;
var createBranch = new MenuItem();