Browse Source

repro commit for itemscontrol causing memory leak.

Dan Walmsley 9 years ago
parent
commit
ab3237a923

+ 73 - 0
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<EditorViewModel>();
+
+            AddDocumentCommand = ReactiveCommand.Create();
+            AddDocumentCommand.Subscribe(_ =>
+            {
+                Documents.Add(new EditorViewModel());
+            });
+        }
+
+        public static ShellViewModel Instance = new ShellViewModel();
+
+        private ObservableCollection<EditorViewModel> documents;
+        public ObservableCollection<EditorViewModel> 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<object> 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<object> CloseCommand { get; }
+    }
+}

+ 14 - 1
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<TestItem> Items { get; }

+ 77 - 0
samples/XamlTestApplicationPcl/Views/MainWindow.xaml

@@ -316,6 +316,83 @@
           <local:TestScrollable/>
         </ScrollViewer>
       </TabItem>
+      <TabItem Header="Mem Leak Repro">
+        <Grid DataContext="{Binding Shell}">
+            <StackPanel>
+              
+            <TabStrip Name="strip"  Items="{Binding Documents}" SelectedItem="{Binding SelectedDocument, Mode=TwoWay}" Focusable="false">
+              <TabStrip.Styles>                
+
+                <Style Selector="TabStripItem">
+                  <Setter Property="Height" Value="20" />
+                  <Setter Property="Background" Value="#2D2D30" />
+                  <Setter Property="BorderBrush" Value="#3E3E42" />
+                  <Setter Property="BorderThickness" Value="0" />
+                  <Setter Property="Margin" Value="0 0 0 -1" />
+                  <Setter Property="Padding" Value="4 0 4 0" />
+                  <Setter Property="FontSize" Value="12"/>
+                </Style>
+                <Style Selector="TabStripItem:pointerover">
+                  <Setter Property="Background" Value="#1c97ea" />
+                </Style>
+                <Style Selector="TabStripItem:selected">
+                  <Setter Property="Background" Value="#007ACC" />
+                </Style>
+              </TabStrip.Styles>
+
+              <TabStrip.DataTemplates>
+                <DataTemplate>
+                  <StackPanel Orientation="Horizontal" Gap="2">                    
+                    <TextBlock Text="{Binding Title}" Foreground="WhiteSmoke" Margin="2"/>                    
+                    <Button Height="14" Width="14">
+                      <Button.Styles>
+                        <Style Selector="Button">
+                          <Setter Property="BorderThickness" Value="0"/>
+                          <Setter Property="Padding" Value="0"/>
+                          <Setter Property="Margin" Value="0"/>
+                          <Setter Property="Background" Value="Transparent" />
+                        </Style>
+
+                        <Style Selector="Button:pointerover">
+                          <Setter Property="Background" Value="#1c97ea" />
+                        </Style>
+                      </Button.Styles>
+                      <Path Margin="2" Stretch="Uniform" UseLayoutRounding="False" Data="M16,12V4H17V2H7V4H8V12L6,14V16H11.2V22H12.8V16H18V14L16,12Z" Fill="WhiteSmoke" />
+
+                    </Button>
+
+                    <Button Height="14" Width="14" Command="{Binding CloseCommand}">
+                      <Button.Styles>
+                        <Style Selector="Button">
+                          <Setter Property="BorderThickness" Value="0"/>
+                          <Setter Property="Padding" Value="0"/>
+                          <Setter Property="Margin" Value="0"/>
+                          <Setter Property="Background" Value="Transparent" />
+                        </Style>
+                        <Style Selector="Button:pointerover">
+                          <Setter Property="Background" Value="#1c97ea" />
+                        </Style>
+                      </Button.Styles>
+                      <Path Margin="2" Stretch="Uniform" UseLayoutRounding="False" Data="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" Fill="WhiteSmoke" />
+                    </Button>
+                  </StackPanel>                  
+                </DataTemplate>
+              </TabStrip.DataTemplates>
+            </TabStrip>
+            <Grid Background="#007ACC" Height="2" />
+              <Button Content="AddTab" Command="{Binding AddDocumentCommand}" Width="50" Height="30" />
+          
+
+          <Carousel Items="{Binding Documents}" SelectedIndex="{Binding #strip.SelectedIndex}" IsVirtualized="false">
+            <Carousel.DataTemplates>
+              <DataTemplate>
+                <TextBox Text="{Binding Text}" />
+              </DataTemplate>
+            </Carousel.DataTemplates>
+          </Carousel>
+            </StackPanel>
+        </Grid>
+      </TabItem>
     </TabControl>
   </Grid>
 </Window>

+ 1 - 0
samples/XamlTestApplicationPcl/XamlTestApplicationPcl.csproj

@@ -42,6 +42,7 @@
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TestScrollable.cs" />
+    <Compile Include="ViewModels\EditorViewModel.cs" />
     <Compile Include="ViewModels\MainWindowViewModel.cs" />
     <Compile Include="ViewModels\TestItem.cs" />
     <Compile Include="ViewModels\TestNode.cs" />