Browse Source

updated repro design.

pull/519/head
Dan Walmsley 11 years ago
parent
commit
8595eb58b3
  1. 32
      samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs
  2. 3
      samples/XamlTestApplicationPcl/Views/MainWindow.xaml

32
samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs

@ -1,4 +1,6 @@
namespace XamlTestApplication.ViewModels using Perspex.Threading;
namespace XamlTestApplication.ViewModels
{ {
using ReactiveUI; using ReactiveUI;
using System; using System;
@ -19,6 +21,12 @@
{ {
Documents.Add(new EditorViewModel()); Documents.Add(new EditorViewModel());
}); });
GCCommand = ReactiveCommand.Create();
GCCommand.Subscribe(_ =>
{
GC.Collect();
});
} }
public static ShellViewModel Instance = new ShellViewModel(); public static ShellViewModel Instance = new ShellViewModel();
@ -38,14 +46,28 @@
set { this.RaiseAndSetIfChanged(ref selectedDocument, value); } set { this.RaiseAndSetIfChanged(ref selectedDocument, value); }
} }
private int instanceCount;
public int InstanceCount
{
get { return instanceCount; }
set { this.RaiseAndSetIfChanged(ref instanceCount, value); }
}
public ReactiveCommand<object> AddDocumentCommand { get; } public ReactiveCommand<object> AddDocumentCommand { get; }
public ReactiveCommand<object> GCCommand { get; }
} }
public class EditorViewModel : ReactiveObject public class EditorViewModel : ReactiveObject
{ {
private static int InstanceCount = 0;
public EditorViewModel() public EditorViewModel()
{ {
InstanceCount++;
ShellViewModel.Instance.InstanceCount = InstanceCount;
text = "This is some text."; text = "This is some text.";
CloseCommand = ReactiveCommand.Create(); CloseCommand = ReactiveCommand.Create();
@ -59,6 +81,14 @@
~EditorViewModel() ~EditorViewModel()
{ {
//System.Console.WriteLine("EVM Destructed");
InstanceCount--;
Dispatcher.UIThread.InvokeAsync(() =>
{
ShellViewModel.Instance.InstanceCount = InstanceCount;
});
} }
private string text; private string text;

3
samples/XamlTestApplicationPcl/Views/MainWindow.xaml

@ -381,7 +381,8 @@
</TabStrip> </TabStrip>
<Grid Background="#007ACC" Height="2" /> <Grid Background="#007ACC" Height="2" />
<Button Content="AddTab" Command="{Binding AddDocumentCommand}" Width="50" Height="30" /> <Button Content="AddTab" Command="{Binding AddDocumentCommand}" Width="50" Height="30" />
<Button Content="GC.Collecy" Command="{Binding GCCommand}" Width="50" Height="30" />
<TextBox Text="{Binding InstanceCount}" />
<Carousel Items="{Binding Documents}" SelectedIndex="{Binding #strip.SelectedIndex}" IsVirtualized="false"> <Carousel Items="{Binding Documents}" SelectedIndex="{Binding #strip.SelectedIndex}" IsVirtualized="false">
<Carousel.DataTemplates> <Carousel.DataTemplates>

Loading…
Cancel
Save