From 9940464fa192c38ee77dd037f2a01ec695c249e0 Mon Sep 17 00:00:00 2001 From: danwalmsley Date: Tue, 19 Apr 2016 13:06:30 +0100 Subject: [PATCH 01/14] fix for carousel presenter in isvirtualized = false --- .../Presenters/CarouselPresenter.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Perspex.Controls/Presenters/CarouselPresenter.cs b/src/Perspex.Controls/Presenters/CarouselPresenter.cs index 1a7de96a16..5ea2c26c98 100644 --- a/src/Perspex.Controls/Presenters/CarouselPresenter.cs +++ b/src/Perspex.Controls/Presenters/CarouselPresenter.cs @@ -103,7 +103,25 @@ namespace Perspex.Controls.Presenters /// protected override void ItemsChanged(NotifyCollectionChangedEventArgs e) { - // TODO: Handle items changing. + // TODO: Handle items changing. + switch(e.Action) + { + case NotifyCollectionChangedAction.Remove: + if (!IsVirtualized) + { + var generator = ItemContainerGenerator; + + foreach (var removed in e.OldItems) + { + var currentContainer = generator.Containers.FirstOrDefault((c) => c.Item == removed); + var index = generator.IndexFromContainer(currentContainer.ContainerControl); + + Panel.Children.Remove(currentContainer.ContainerControl); + generator.Dematerialize(index, 1); + } + } + break; + } } /// From ab3237a92310f6d438a8bcacc77800698ac5171d Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 19 Apr 2016 22:13:00 +0100 Subject: [PATCH 02/14] repro commit for itemscontrol causing memory leak. --- .../ViewModels/EditorViewModel.cs | 73 ++++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 15 +++- .../Views/MainWindow.xaml | 77 +++++++++++++++++++ .../XamlTestApplicationPcl.csproj | 1 + 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs diff --git a/samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs b/samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs new file mode 100644 index 0000000000..91ce6fb620 --- /dev/null +++ b/samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs @@ -0,0 +1,73 @@ +namespace XamlTestApplication.ViewModels +{ + using ReactiveUI; + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + + public class ShellViewModel : ReactiveObject + { + private ShellViewModel() + { + documents = new ObservableCollection(); + + AddDocumentCommand = ReactiveCommand.Create(); + AddDocumentCommand.Subscribe(_ => + { + Documents.Add(new EditorViewModel()); + }); + } + + public static ShellViewModel Instance = new ShellViewModel(); + + private ObservableCollection documents; + public ObservableCollection Documents + { + get { return documents; } + set { this.RaiseAndSetIfChanged(ref documents, value); } + } + + private EditorViewModel selectedDocument; + + public EditorViewModel SelectedDocument + { + get { return selectedDocument; } + set { this.RaiseAndSetIfChanged(ref selectedDocument, value); } + } + + + public ReactiveCommand AddDocumentCommand { get; } + } + + public class EditorViewModel : ReactiveObject + { + public EditorViewModel() + { + text = "This is some text."; + + CloseCommand = ReactiveCommand.Create(); + + CloseCommand.Subscribe(_ => + { + ShellViewModel.Instance.Documents.Remove(this); + }); + } + + ~EditorViewModel() + { + + } + + private string text; + public string Text + { + get { return text; } + set { this.RaiseAndSetIfChanged(ref text, value); } + } + + public ReactiveCommand CloseCommand { get; } + } +} diff --git a/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs b/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs index 3ae72e138c..f584493097 100644 --- a/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs +++ b/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs @@ -56,7 +56,11 @@ namespace XamlTestApplication.ViewModels } }; - CollapseNodesCommand = ReactiveCommand.Create(); + + + + + CollapseNodesCommand = ReactiveCommand.Create(); CollapseNodesCommand.Subscribe(_ => ExpandNodes(false)); ExpandNodesCommand = ReactiveCommand.Create(); ExpandNodesCommand.Subscribe(_ => ExpandNodes(true)); @@ -77,6 +81,15 @@ namespace XamlTestApplication.ViewModels ofd.ShowAsync(); }); + shell = ShellViewModel.Instance; + } + + private ShellViewModel shell; + + public ShellViewModel Shell + { + get { return shell; } + set { shell = value; } } public List Items { get; } diff --git a/samples/XamlTestApplicationPcl/Views/MainWindow.xaml b/samples/XamlTestApplicationPcl/Views/MainWindow.xaml index 1dc8575178..8da066ac26 100644 --- a/samples/XamlTestApplicationPcl/Views/MainWindow.xaml +++ b/samples/XamlTestApplicationPcl/Views/MainWindow.xaml @@ -316,6 +316,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + +