fix: SelectableTextBlock does not re-draw after Text property changed (#906)

This commit is contained in:
leo 2025-01-14 21:02:32 +08:00
parent c8aecc00cc
commit 1c8d4d312a
No known key found for this signature in database
2 changed files with 32 additions and 12 deletions

View file

@ -20,13 +20,13 @@
<StackPanel Grid.Column="1" Margin="16,0,8,0" Orientation="Vertical">
<TextBlock Classes="group_header_label" Margin="0" Text="{DynamicResource Text.CommitDetail.Info.Author}"/>
<Grid Margin="0,10,0,8" ColumnDefinitions="Auto,*" ClipToBounds="True">
<SelectableTextBlock Grid.Column="0" Text="{Binding Author.Name}" Margin="2,0,8,0"/>
<SelectableTextBlock Grid.Column="1" Text="{Binding Author.Email}" ToolTip.Tip="{Binding Author.Email}" Foreground="{DynamicResource Brush.FG2}" TextTrimming="CharacterEllipsis"/>
<v:EnhancedSelectableTextBlock Grid.Column="0" Text="{Binding Author.Name}" Margin="2,0,8,0"/>
<v:EnhancedSelectableTextBlock Grid.Column="1" Text="{Binding Author.Email}" ToolTip.Tip="{Binding Author.Email}" Foreground="{DynamicResource Brush.FG2}" TextTrimming="CharacterEllipsis"/>
</Grid>
<SelectableTextBlock Text="{Binding AuthorTimeStr}"
Margin="2,0,0,0"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
Foreground="{DynamicResource Brush.FG2}"/>
<v:EnhancedSelectableTextBlock Text="{Binding AuthorTimeStr}"
Margin="2,0,0,0"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
</Grid>
@ -36,13 +36,13 @@
<StackPanel Grid.Column="1" Margin="16,0,8,0" Orientation="Vertical">
<TextBlock Classes="group_header_label" Margin="0" Text="{DynamicResource Text.CommitDetail.Info.Committer}"/>
<Grid Margin="0,10,0,8" ColumnDefinitions="Auto,*" ClipToBounds="True">
<SelectableTextBlock Grid.Column="0" Text="{Binding Committer.Name}" Margin="2,0,8,0"/>
<SelectableTextBlock Grid.Column="1" Text="{Binding Committer.Email}" ToolTip.Tip="{Binding Committer.Email}" Foreground="{DynamicResource Brush.FG2}" TextTrimming="CharacterEllipsis"/>
<v:EnhancedSelectableTextBlock Grid.Column="0" Text="{Binding Committer.Name}" Margin="2,0,8,0"/>
<v:EnhancedSelectableTextBlock Grid.Column="1" Text="{Binding Committer.Email}" ToolTip.Tip="{Binding Committer.Email}" Foreground="{DynamicResource Brush.FG2}" TextTrimming="CharacterEllipsis"/>
</Grid>
<SelectableTextBlock Text="{Binding CommitterTimeStr}"
Margin="2,0,0,0"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
Foreground="{DynamicResource Brush.FG2}"/>
<v:EnhancedSelectableTextBlock Text="{Binding CommitterTimeStr}"
Margin="2,0,0,0"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
</Grid>
</UniformGrid>

View file

@ -0,0 +1,20 @@
using System;
using Avalonia;
using Avalonia.Controls;
namespace SourceGit.Views
{
public class EnhancedSelectableTextBlock : SelectableTextBlock
{
protected override Type StyleKeyOverride => typeof(SelectableTextBlock);
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == TextProperty)
UpdateLayout();
}
}
}