Fix naming in custom-dependency-properties snippet (#1204)

* Fix naming

* Simplify identifier assignment

* Simplify identifier assignment
This commit is contained in:
Tris Shores
2021-11-05 08:19:39 -07:00
committed by GitHub
parent 7d5a5bd5b9
commit b82ed37802
4 changed files with 15 additions and 27 deletions
@@ -69,20 +69,17 @@ namespace CodeSampleCsharp
public class Aquarium : DependencyObject public class Aquarium : DependencyObject
{ {
// Register a dependency property with the specified property name, // Register a dependency property with the specified property name,
// property type, and owner type. // property type, and owner type. Store the dependency property
private static readonly DependencyProperty s_aquariumContentsProperty = // identifier as a public static readonly member of the class.
public static readonly DependencyProperty AquariumContentsProperty =
DependencyProperty.Register( DependencyProperty.Register(
name: "AquariumContents", name: "AquariumContents",
propertyType: typeof(List<FrameworkElement>), propertyType: typeof(List<FrameworkElement>),
ownerType: typeof(Aquarium) ownerType: typeof(Aquarium)
); );
// Store the dependency property identifier as a static member of the class.
public static readonly DependencyProperty AquariumContentsProperty =
s_aquariumContentsProperty;
// Set the default collection value in a class constructor. // Set the default collection value in a class constructor.
public Aquarium() => SetValue(s_aquariumContentsProperty, new List<FrameworkElement>()); public Aquarium() => SetValue(AquariumContentsProperty, new List<FrameworkElement>());
// Declare a read-write property. // Declare a read-write property.
public List<FrameworkElement> AquariumContents public List<FrameworkElement> AquariumContents
@@ -76,20 +76,17 @@
Inherits DependencyObject Inherits DependencyObject
' Register a dependency property with the specified property name, ' Register a dependency property with the specified property name,
' property type, and owner type. ' property type, and owner type. Store the dependency property
Private Shared ReadOnly s_aquariumContentsProperty As DependencyProperty = ' identifier as a static member of the class.
Public Shared ReadOnly AquariumContentsProperty As DependencyProperty =
DependencyProperty.Register( DependencyProperty.Register(
name:="AquariumContents", name:="AquariumContents",
propertyType:=GetType(List(Of FrameworkElement)), propertyType:=GetType(List(Of FrameworkElement)),
ownerType:=GetType(Aquarium)) ownerType:=GetType(Aquarium))
' Store the dependency property identifier as a static member of the class.
Public Shared ReadOnly AquariumContentsProperty As DependencyProperty =
s_aquariumContentsProperty
' Set the default collection value in a class constructor. ' Set the default collection value in a class constructor.
Public Sub New() Public Sub New()
SetValue(s_aquariumContentsProperty, New List(Of FrameworkElement)()) SetValue(AquariumContentsProperty, New List(Of FrameworkElement)())
End Sub End Sub
' Declare a read-write property. ' Declare a read-write property.
@@ -18,8 +18,9 @@ namespace CodeSampleCsharp
//<RegisterDependencyPropertyWithWrapper> //<RegisterDependencyPropertyWithWrapper>
//<RegisterDependencyProperty> //<RegisterDependencyProperty>
// Register a dependency property with the specified property name, // Register a dependency property with the specified property name,
// property type, owner type, and property metadata. // property type, owner type, and property metadata. Store the dependency
private static readonly DependencyProperty s_aquariumGraphicProperty = // property identifier as a public static readonly member of the class.
public static readonly DependencyProperty AquariumGraphicProperty =
DependencyProperty.Register( DependencyProperty.Register(
name: "AquariumGraphic", name: "AquariumGraphic",
propertyType: typeof(Uri), propertyType: typeof(Uri),
@@ -29,14 +30,10 @@ namespace CodeSampleCsharp
flags: FrameworkPropertyMetadataOptions.AffectsRender, flags: FrameworkPropertyMetadataOptions.AffectsRender,
propertyChangedCallback: new PropertyChangedCallback(OnUriChanged)) propertyChangedCallback: new PropertyChangedCallback(OnUriChanged))
); );
// Store the dependency property identifier as a static member of the class.
public static readonly DependencyProperty AquariumGraphicProperty =
s_aquariumGraphicProperty;
//</RegisterDependencyProperty> //</RegisterDependencyProperty>
// Declare a read-write property. // Declare a read-write property.
public Uri AquariumContents public Uri AquariumGraphic
{ {
get => (Uri)GetValue(AquariumGraphicProperty); get => (Uri)GetValue(AquariumGraphicProperty);
set => SetValue(AquariumGraphicProperty, value); set => SetValue(AquariumGraphicProperty, value);
@@ -17,8 +17,9 @@
'<RegisterDependencyPropertyWithWrapper> '<RegisterDependencyPropertyWithWrapper>
'<RegisterDependencyProperty> '<RegisterDependencyProperty>
' Register a dependency property with the specified property name, ' Register a dependency property with the specified property name,
' property type, owner type, and property metadata. ' property type, owner type, and property metadata. Store the dependency
Private Shared ReadOnly s_aquariumGraphicProperty As DependencyProperty = ' property identifier as a public static readonly member of the class.
Public Shared ReadOnly AquariumGraphicProperty As DependencyProperty =
DependencyProperty.Register( DependencyProperty.Register(
name:="AquariumGraphic", name:="AquariumGraphic",
propertyType:=GetType(Uri), propertyType:=GetType(Uri),
@@ -27,10 +28,6 @@
defaultValue:=New Uri("http://www.contoso.com/aquarium-graphic.jpg"), defaultValue:=New Uri("http://www.contoso.com/aquarium-graphic.jpg"),
flags:=FrameworkPropertyMetadataOptions.AffectsRender, flags:=FrameworkPropertyMetadataOptions.AffectsRender,
propertyChangedCallback:=New PropertyChangedCallback(AddressOf OnUriChanged))) propertyChangedCallback:=New PropertyChangedCallback(AddressOf OnUriChanged)))
' Store the dependency property identifier as a static member of the class.
Public Shared ReadOnly AquariumGraphicProperty As DependencyProperty =
s_aquariumGraphicProperty
'</RegisterDependencyProperty> '</RegisterDependencyProperty>
' Declare a read-write property. ' Declare a read-write property.