Browse Source

Update BindingTest to display data template.

Based on selected list item. Trying to reproduce the leak seen in
Core2D.
Steven Kirk 9 years ago
parent
commit
e09495749f

+ 3 - 4
samples/BindingTest/BindingTest.csproj

@@ -84,10 +84,9 @@
       <DependentUpon>MainWindow.paml</DependentUpon>
     </Compile>
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="TestUserControl.paml.cs">
-      <DependentUpon>TestUserControl.paml</DependentUpon>
+    <Compile Include="TestItemView.paml.cs">
+      <DependentUpon>TestItemView.paml</DependentUpon>
     </Compile>
-    <Compile Include="ViewModels\TestUserControlViewModel.cs" />
     <Compile Include="ViewModels\MainWindowViewModel.cs" />
     <Compile Include="ViewModels\TestItem.cs" />
   </ItemGroup>
@@ -97,7 +96,7 @@
       <SubType>Designer</SubType>
     </EmbeddedResource>
     <None Include="packages.config" />
-    <EmbeddedResource Include="TestUserControl.paml" />
+    <EmbeddedResource Include="TestItemView.paml" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\src\Markup\Perspex.Markup.Xaml\Perspex.Markup.Xaml.csproj">

+ 13 - 5
samples/BindingTest/MainWindow.paml

@@ -1,6 +1,12 @@
 <Window xmlns="https://github.com/perspex"
         xmlns:vm="clr-namespace:BindingTest.ViewModels;assembly=BindingTest"
         xmlns:local="clr-namespace:BindingTest;assembly=BindingTest">
+  <Window.Styles>
+    <Style Selector="TextBlock.h1">
+      <Setter Property="FontSize" Value="18"/>
+    </Style>
+  </Window.Styles>
+  
   <TabControl>
     <TabItem Header="Basic">
       <StackPanel Orientation="Vertical">
@@ -53,12 +59,14 @@
           <TextBlock FontSize="16" Text="Multiple"/>
           <ListBox Items="{Binding Items}" SelectionMode="Multiple" SelectedItems="{Binding SelectedItems}"/>
         </StackPanel>
+        <ContentControl Content="{Binding SelectedItems[0]}">
+          <ContentControl.DataTemplates>
+            <DataTemplate DataType="vm:TestItem">
+              <local:TestItemView></local:TestItemView>
+            </DataTemplate>
+          </ContentControl.DataTemplates>
+        </ContentControl>
       </StackPanel>
     </TabItem>
-    <TabItem Header="UserControl">
-      <local:TestUserControl DataContext="{Binding UserControl}"
-                             HorizontalAlignment="Center"
-                             VerticalAlignment="Center"/>
-    </TabItem>
   </TabControl>
 </Window>

+ 6 - 0
samples/BindingTest/TestItemView.paml

@@ -0,0 +1,6 @@
+<UserControl xmlns="https://github.com/perspex">
+  <StackPanel>
+    <TextBlock Classes="h1" Text="{Binding StringValue}"/>
+    <TextBlock Text="{Binding Detail}"/>
+  </StackPanel>
+</UserControl>

+ 2 - 2
samples/BindingTest/TestUserControl.paml.cs → samples/BindingTest/TestItemView.paml.cs

@@ -3,9 +3,9 @@ using Perspex.Markup.Xaml;
 
 namespace BindingTest
 {
-    public class TestUserControl : UserControl
+    public class TestItemView : UserControl
     {
-        public TestUserControl()
+        public TestItemView()
         {
             this.InitializeComponent();
         }

+ 0 - 3
samples/BindingTest/TestUserControl.paml

@@ -1,3 +0,0 @@
-<UserControl xmlns="https://github.com/perspex">
-  <TextBlock Text="{Binding Content}"/>
-</UserControl>

+ 2 - 2
samples/BindingTest/ViewModels/MainWindowViewModel.cs

@@ -16,7 +16,8 @@ namespace BindingTest.ViewModels
             Items = new ObservableCollection<TestItem>(
                 Enumerable.Range(0, 20).Select(x => new TestItem
                 {
-                    StringValue = "Item " + x
+                    StringValue = "Item " + x,
+                    Detail = "Item " + " details",
                 }));
 
             SelectedItems = new ObservableCollection<TestItem>();
@@ -32,7 +33,6 @@ namespace BindingTest.ViewModels
         public ObservableCollection<TestItem> Items { get; }
         public ObservableCollection<TestItem> SelectedItems { get; }
         public ReactiveCommand<object> ShuffleItems { get; }
-        public TestUserControlViewModel UserControl { get; } = new TestUserControlViewModel();
 
         public string BooleanString
         {

+ 10 - 3
samples/BindingTest/ViewModels/TestItem.cs

@@ -4,12 +4,19 @@ namespace BindingTest.ViewModels
 {
     public class TestItem : ReactiveObject
     {
-        private string stringValue = "String Value";
+        private string _stringValue = "String Value";
+        private string _detail;
 
         public string StringValue
         {
-            get { return stringValue; }
-            set { this.RaiseAndSetIfChanged(ref this.stringValue, value); }
+            get { return _stringValue; }
+            set { this.RaiseAndSetIfChanged(ref this._stringValue, value); }
+        }
+
+        public string Detail
+        {
+            get { return _detail; }
+            set { this.RaiseAndSetIfChanged(ref this._detail, value); }
         }
     }
 }

+ 0 - 9
samples/BindingTest/ViewModels/TestUserControlViewModel.cs

@@ -1,9 +0,0 @@
-using ReactiveUI;
-
-namespace BindingTest.ViewModels
-{
-    public class TestUserControlViewModel : ReactiveObject
-    {
-        public string Content { get; } = "User Control Content";
-    }
-}