Skip to content

Commit

Permalink
Clarify WPF metadata return type (#1694)
Browse files Browse the repository at this point in the history
* move code to right folder; add snippet

* Clarify metadata type
  • Loading branch information
adegeo authored Sep 1, 2023
1 parent 8df1ad2 commit 9b56103
Show file tree
Hide file tree
Showing 35 changed files with 111 additions and 26 deletions.
57 changes: 31 additions & 26 deletions dotnet-desktop-guide/net/wpf/data/index.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
bindings.Metadata.PrintMetadata();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Intrinsics.Arm;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace bindings
{
class Metadata
{
//<print_metadata>
public static void PrintMetadata()
{
// Get the metadata for the property
PropertyMetadata metadata = TextBox.TextProperty.GetMetadata(typeof(TextBox));

// Check if metadata type is FrameworkPropertyMetadata
if (metadata is FrameworkPropertyMetadata frameworkMetadata)
{
System.Diagnostics.Debug.WriteLine($"TextBox.Text property metadata:");
System.Diagnostics.Debug.WriteLine($" BindsTwoWayByDefault: {frameworkMetadata.BindsTwoWayByDefault}");
System.Diagnostics.Debug.WriteLine($" IsDataBindingAllowed: {frameworkMetadata.IsDataBindingAllowed}");
System.Diagnostics.Debug.WriteLine($" AffectsArrange: {frameworkMetadata.AffectsArrange}");
System.Diagnostics.Debug.WriteLine($" AffectsMeasure: {frameworkMetadata.AffectsMeasure}");
System.Diagnostics.Debug.WriteLine($" AffectsRender: {frameworkMetadata.AffectsRender}");
System.Diagnostics.Debug.WriteLine($" Inherits: {frameworkMetadata.Inherits}");
}

/* Displays:
*
* TextBox.Text property metadata:
* BindsTwoWayByDefault: True
* IsDataBindingAllowed: True
* AffectsArrange: False
* AffectsMeasure: False
* AffectsRender: False
* Inherits: False
*/
}
//</print_metadata>
}
}
34 changes: 34 additions & 0 deletions dotnet-desktop-guide/net/wpf/data/snippets/index/vb/Metadata.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Public Class Metadata

'<print_metadata>
Public Shared Sub PrintMetadata()

Dim metadata As PropertyMetadata = TextBox.TextProperty.GetMetadata(GetType(TextBox))
Dim frameworkMetadata As FrameworkPropertyMetadata = TryCast(metadata, FrameworkPropertyMetadata)

If frameworkMetadata IsNot Nothing Then

System.Diagnostics.Debug.WriteLine($"TextBox.Text property metadata:")
System.Diagnostics.Debug.WriteLine($" BindsTwoWayByDefault: {frameworkMetadata.BindsTwoWayByDefault}")
System.Diagnostics.Debug.WriteLine($" IsDataBindingAllowed: {frameworkMetadata.IsDataBindingAllowed}")
System.Diagnostics.Debug.WriteLine($" AffectsArrange: {frameworkMetadata.AffectsArrange}")
System.Diagnostics.Debug.WriteLine($" AffectsMeasure: {frameworkMetadata.AffectsMeasure}")
System.Diagnostics.Debug.WriteLine($" AffectsRender: {frameworkMetadata.AffectsRender}")
System.Diagnostics.Debug.WriteLine($" Inherits: {frameworkMetadata.Inherits}")

' Displays:
'
' TextBox.Text property metadata:
' BindsTwoWayByDefault: True
' IsDataBindingAllowed: True
' AffectsArrange: False
' AffectsMeasure: False
' AffectsRender: False
' Inherits: False
End If


End Sub
'</print_metadata>

End Class

0 comments on commit 9b56103

Please sign in to comment.