diff --git a/dotnet-desktop-guide/net/wpf/properties/attached-properties-overview.md b/dotnet-desktop-guide/net/wpf/properties/attached-properties-overview.md index b2f2e87d58..d1690430a7 100644 --- a/dotnet-desktop-guide/net/wpf/properties/attached-properties-overview.md +++ b/dotnet-desktop-guide/net/wpf/properties/attached-properties-overview.md @@ -95,9 +95,9 @@ The following example shows how to register a dependency property using the (object target)`, where: +The `get` accessor method signature is `public static object Get(DependencyObject target)`, where: -- `target` is the object from which the attached property is read. The `target` type can be more specific than `object`. For example, the accessor method types the `target` as because the attached property is intended to be set on `UIElement` instances. +- `target` is the from which the attached property is read. The `target` type can be more specific than `DependencyObject`. For example, the accessor method types the `target` as because the attached property is intended to be set on `UIElement` instances. `UiElement` indirectly derives from `DependencyObject`. - The return type can be more specific than `object`. For example, the method types the returned value as because the return value should be a `Dock` enumeration. > [!NOTE] @@ -105,9 +105,9 @@ The `get` accessor method signature is `public static object Get( #### The Set accessor -The `set` accessor method signature is `public static void Set(object target, object value)`, where: +The `set` accessor method signature is `public static void Set(DependencyObject target, object value)`, where: -- `target` is the object on which the attached property is written. The `target` type can be more specific than `object`. For example, the method types the `target` as because the attached property is intended to be set on instances. +- `target` is the on which the attached property is written. The `target` type can be more specific than `DependencyObject`. For example, the method types the `target` as because the attached property is intended to be set on instances. `UiElement` indirectly derives from `DependencyObject`. - The `value` type can be more specific than `object`. For example, the method requires a value. The XAML loader needs to be able to generate the `value` type from the markup string that represents the attached property value. So, there must be type conversion, value serializer, or markup extension support for the type you use. ### Attached property attributes diff --git a/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/csharp/MainWindow.xaml.cs index 58604d2045..786d91b291 100644 --- a/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/csharp/MainWindow.xaml.cs +++ b/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/csharp/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using System.Windows.Controls; namespace CodeSampleCsharp @@ -13,6 +14,12 @@ public MainWindow() InitializeComponent(); SetAttachedPropertyInCode(); + + // Test get/set accessors. + Aquarium aquarium = new(); + Aquarium.SetHasFish(aquarium, true); + bool hasFish = Aquarium.GetHasFish(aquarium); + Debug.WriteLine($"Has fish: {hasFish}"); } public static void SetAttachedPropertyInCode() @@ -32,7 +39,7 @@ public static void SetAttachedPropertyInCode() } // - public class Aquarium : DependencyObject + public class Aquarium : UIElement { // Register an attached dependency property with the specified // property name, property type, owner type, and property metadata. diff --git a/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/vb/MainWindow.xaml.vb index 6a6c16c22d..2e438647cd 100644 --- a/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/vb/MainWindow.xaml.vb +++ b/dotnet-desktop-guide/net/wpf/properties/snippets/attached-properties-overview/vb/MainWindow.xaml.vb @@ -10,6 +10,12 @@ InitializeComponent() SetAttachedPropertyInCode() + + ' Test get/set accessors. + Dim aquarium As New Aquarium() + aquarium.SetHasFish(aquarium, True) + Dim hasFish As Boolean = aquarium.GetHasFish(aquarium) + Debug.WriteLine($"Has fish: {hasFish}") End Sub Public Shared Sub SetAttachedPropertyInCode() @@ -30,7 +36,7 @@ ' Public Class Aquarium - Inherits DependencyObject + Inherits UIElement ' Register an attached dependency property with the specified ' property name, property type, owner type, and property metadata. diff --git a/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/csharp/MainWindow.xaml.cs index 7c61da6594..1a8b906231 100644 --- a/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/csharp/MainWindow.xaml.cs +++ b/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/csharp/MainWindow.xaml.cs @@ -1,5 +1,5 @@ -using System.Windows; -using System.Windows.Controls; +using System.Diagnostics; +using System.Windows; namespace CodeSampleCsharp { @@ -8,11 +8,20 @@ namespace CodeSampleCsharp /// public partial class MainWindow : Window { - public MainWindow() => InitializeComponent(); + public MainWindow() + { + InitializeComponent(); + + // Test get/set accessors. + Aquarium aquarium = new(); + Aquarium.SetHasFish(aquarium, true); + bool hasFish = Aquarium.GetHasFish(aquarium); + Debug.WriteLine($"Has fish: {hasFish}"); + } } // - public class Aquarium : DependencyObject + public class Aquarium : UIElement { // Register an attached dependency property with the specified // property name, property type, owner type, and property metadata. diff --git a/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/vb/MainWindow.xaml.vb index b1b3e45975..6c59950698 100644 --- a/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/vb/MainWindow.xaml.vb +++ b/dotnet-desktop-guide/net/wpf/properties/snippets/how-to-register-an-attached-property/vb/MainWindow.xaml.vb @@ -8,13 +8,19 @@ Public Sub New() InitializeComponent() + + ' Test get/set accessors. + Dim aquarium As New Aquarium() + Aquarium.SetHasFish(aquarium, True) + Dim hasFish As Boolean = Aquarium.GetHasFish(aquarium) + Debug.WriteLine($"Has fish: {hasFish}") End Sub End Class ' - Public Class Aquarium - Inherits DependencyObject + Public Class Aquarium + Inherits UIElement ' Register an attached dependency property with the specified ' property name, property type, owner type, and property metadata. diff --git a/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md b/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md index b7634ef279..50caefdf5a 100644 --- a/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md +++ b/dotnet-desktop-guide/net/wpf/windows/dialog-boxes-overview.md @@ -16,7 +16,7 @@ Windows Presentation Foundation (WPF) provides ways for you to design your own d - Display specific information to users. - Gather information from users. - Both display and gather information. -- Display an operating system prompt, such a print window. +- Display an operating system prompt, such as print window. - Select a file or folder. These types of windows are known as _dialog boxes_. A dialog box can be displayed in two ways: modal and modeless.