mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 19:55:00 +00:00
optimize<*>: use custom view locator instead of ContentControl.DataTemplates to avoid memory leak.
This commit is contained in:
parent
27d4dd5f64
commit
60e664ab26
9 changed files with 77 additions and 62 deletions
|
@ -1,11 +1,45 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using SourceGit.ViewModels;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.Views {
|
||||
public class RepositorySubView : Border {
|
||||
public static readonly StyledProperty<object> DataProperty =
|
||||
AvaloniaProperty.Register<RepositorySubView, object>(nameof(Data), false);
|
||||
|
||||
public object Data {
|
||||
get => GetValue(DataProperty);
|
||||
set => SetValue(DataProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(Border);
|
||||
|
||||
static RepositorySubView() {
|
||||
DataProperty.Changed.AddClassHandler<RepositorySubView>((view, ev) => {
|
||||
var data = view.Data;
|
||||
|
||||
if (data == null) {
|
||||
view.Child = null;
|
||||
} else if (data is ViewModels.Histories) {
|
||||
view.Child = new Histories { DataContext = data };
|
||||
} else if (data is ViewModels.WorkingCopy) {
|
||||
view.Child = new WorkingCopy { DataContext = data };
|
||||
} else if (data is ViewModels.StashesPage) {
|
||||
view.Child = new StashesPage { DataContext = data };
|
||||
} else {
|
||||
view.Child = null;
|
||||
}
|
||||
|
||||
GC.Collect();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Repository : UserControl {
|
||||
public Repository() {
|
||||
InitializeComponent();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue