perf: 优化绑定

This commit is contained in:
uye
2025-12-08 17:02:22 +08:00
parent 6c4c92f26b
commit 4cc0bc55d2
3 changed files with 32 additions and 23 deletions

File diff suppressed because one or more lines are too long

View File

@@ -150,10 +150,16 @@ public class TaskQueueViewModel : Screen
public ObservableCollection<LogItemViewModel> LogItemViewModels { get; private set; } = [];
/// <summary>
/// Gets or private sets the view models of download-related log items.
/// This is a separate area dedicated to showing download progress/messages.
/// Gets or private sets the single download-related log item.
/// Use a single LogItemViewModel instead of a collection because only one entry is shown.
/// </summary>
public ObservableCollection<LogItemViewModel> DownloadLogItemViewModels { get; private set; } = [];
private LogItemViewModel _downloadLogItemViewModel = new(string.Empty);
public LogItemViewModel DownloadLogItemViewModel
{
get => _downloadLogItemViewModel;
private set => SetAndNotify(ref _downloadLogItemViewModel, value);
}
#region ActionAfterTasks
@@ -895,7 +901,7 @@ public class TaskQueueViewModel : Screen
Execute.OnUIThread(() =>
{
LogItemViewModels.Clear();
DownloadLogItemViewModels.Clear();
DownloadLogItemViewModel = new(string.Empty);
_logger.Information("Main windows log clear.");
_logger.Information("{Empty}", string.Empty);
});
@@ -914,13 +920,12 @@ public class TaskQueueViewModel : Screen
// Keep download area limited to a single entry.
if (string.IsNullOrEmpty(fullText))
{
DownloadLogItemViewModels.Clear();
DownloadLogItemViewModel = new(string.Empty);
return;
}
var log = new LogItemViewModel(fullText, UiLogColor.Download, toolTip: toolTip);
DownloadLogItemViewModels.Clear();
DownloadLogItemViewModels.Add(log);
DownloadLogItemViewModel = log;
});
}

View File

@@ -384,13 +384,13 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Download area: always visible, placed above the main log scroll -->
<ItemsControl
<!-- Download area: shown when there is a download log item -->
<ContentControl
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
d:ItemsSource="{d:SampleData ItemCount=1}"
ItemsSource="{Binding DownloadLogItemViewModels}">
<ItemsControl.ItemTemplate>
Content="{Binding DownloadLogItemViewModel}"
Visibility="{c:Binding 'DownloadLogItemViewModel.Content.Length > 0'}">
<ContentControl.ContentTemplate>
<DataTemplate>
<Grid MaxWidth="400">
<Grid.ColumnDefinitions>
@@ -426,18 +426,18 @@
ForegroundKey="{Binding Color}"
Text="{Binding Content}"
TextWrapping="Wrap" />
<controls:TooltipBlock
Grid.Column="1"
Margin="10,0,0,0"
PathDate="M 0 0 L 0.5 0.5 L 0 1"
PathStrokeThickness="1.5"
TextBlockText=""
Visibility="{c:Binding ShowToolTip}" />
</Grid>
<controls:TooltipBlock
Grid.Column="1"
Margin="10,0,0,0"
PathDate="{StaticResource LogToolTip}"
PathStrokeThickness="1.5"
TextBlockText=""
Visibility="{c:Binding ShowToolTip}" />
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ContentControl.ContentTemplate>
</ContentControl>
<!-- Main log scroll area -->
<hc:ScrollViewer
@@ -492,7 +492,7 @@
<controls:TooltipBlock
Grid.Column="1"
Margin="10,0,0,0"
PathDate="M 0 0 L 0.5 0.5 L 0 1"
PathDate="{StaticResource LogToolTip}"
PathStrokeThickness="1.5"
TextBlockText=""
Visibility="{c:Binding ShowToolTip}" />