From e09c64873765090defd88e4fbb4da9f7b6bd5c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Laban?= Date: Wed, 20 Nov 2024 15:36:36 -0500 Subject: [PATCH] docs: Adjust MarkupExtension sample (cherry picked from commit 1523d19adeba4a4077f7852a9d743eb4394e5dd3) --- .../features/windows-ui-markup-extensions.md | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/articles/features/windows-ui-markup-extensions.md b/doc/articles/features/windows-ui-markup-extensions.md index da1e7d762e9c..6fb35ee6017a 100644 --- a/doc/articles/features/windows-ui-markup-extensions.md +++ b/doc/articles/features/windows-ui-markup-extensions.md @@ -89,17 +89,15 @@ Using the following XAML: ```csharp public class DynamicBindExtension : MarkupExtension { - public DynamicBindExtension(string propertyName) - { - _propertyName = propertyName; - } - string _propertyName; + public DynamicBindExtension() { } + + public string Name { get; set; } = ""; - public override object ProvideValue(IXamlServiceProvider serviceProvider) + protected override object? ProvideValue(IXamlServiceProvider serviceProvider) { var root = ((IRootObjectProvider)serviceProvider.GetService(typeof(IRootObjectProvider))).RootObject; - var info = root.GetType().GetProperty(_propertyName); - return info.GetValue(root); + var info = root.GetType().GetProperty(Name); + return info?.GetValue(root); } } ``` @@ -115,7 +113,13 @@ The following XAML will display “Page Tag”: Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - + + + + + + + ```