Tim U 3 роки тому
батько
коміт
cf6c0991f8

+ 15 - 0
samples/ControlCatalog/Models/Person.cs

@@ -16,6 +16,7 @@ namespace ControlCatalog.Models
         string _firstName;
         string _lastName;
         bool _isBanned;
+        private int _age;
 
         public string FirstName
         {
@@ -59,6 +60,20 @@ namespace ControlCatalog.Models
             }
         }
 
+        
+        /// <summary>
+        ///    Gets or sets the age of the person
+        /// </summary>
+        public int Age
+        {
+            get => _age;
+            set
+            {
+                _age = value;
+                OnPropertyChanged(nameof(Age));
+            }
+        }
+
         Dictionary<string, List<string>> _errorLookup = new Dictionary<string, List<string>>();
 
         void SetError(string propertyName, string error)

+ 12 - 0
samples/ControlCatalog/Pages/DataGridPage.xaml

@@ -64,6 +64,18 @@
               <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" Width="2*" FontSize="{Binding #FontSizeSlider.Value, Mode=OneWay}" />
               <DataGridTextColumn Header="Last" Binding="{Binding LastName}" Width="2*" FontSize="{Binding #FontSizeSlider.Value, Mode=OneWay}" />
               <DataGridCheckBoxColumn Header="Is Banned" Binding="{Binding IsBanned}" Width="*" IsThreeState="{Binding #IsThreeStateCheckBox.IsChecked, Mode=OneWay}" />
+              <DataGridTemplateColumn Header="Age" >
+                <DataGridTemplateColumn.CellTemplate>
+                  <DataTemplate DataType="local:Person">
+                    <TextBlock Text="{Binding Age, StringFormat='{}{0} years'}" VerticalAlignment="Center" HorizontalAlignment="Center" />
+                  </DataTemplate>
+                </DataGridTemplateColumn.CellTemplate>
+                <DataGridTemplateColumn.CellEditingTemplate>
+                  <DataTemplate DataType="local:Person">
+                    <NumericUpDown Value="{Binding Age}" FormatString="N0" HorizontalAlignment="Stretch" Minimum="0" Maximum="120" />
+                  </DataTemplate>
+                </DataGridTemplateColumn.CellEditingTemplate>
+              </DataGridTemplateColumn>
             </DataGrid.Columns>
           </DataGrid>
           <Button Grid.Row="1" Name="btnAdd" Margin="12,0,12,12" Content="Add" HorizontalAlignment="Right" />

+ 3 - 3
samples/ControlCatalog/Pages/DataGridPage.xaml.cs

@@ -48,9 +48,9 @@ namespace ControlCatalog.Pages
 
             var items = new List<Person>
             {
-                new Person { FirstName = "John", LastName = "Doe" },
-                new Person { FirstName = "Elizabeth", LastName = "Thomas", IsBanned = true },
-                new Person { FirstName = "Zack", LastName = "Ward" }
+                new Person { FirstName = "John", LastName = "Doe" , Age = 30},
+                new Person { FirstName = "Elizabeth", LastName = "Thomas", IsBanned = true , Age = 40 },
+                new Person { FirstName = "Zack", LastName = "Ward" , Age = 50 }
             };
             var collectionView3 = new DataGridCollectionView(items);