Skip to content

Commit

Permalink
docs: Adjust MarkupExtension sample
Browse files Browse the repository at this point in the history
(cherry picked from commit 1523d19)
  • Loading branch information
jeromelaban authored and mergify[bot] committed Nov 21, 2024
1 parent 81e7501 commit e09c648
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions doc/articles/features/windows-ui-markup-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
```
Expand All @@ -115,7 +113,13 @@ The following XAML will display “Page Tag”:
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<TextBlock Text="{local:DynamicBind Tag}" />
<ContentControl>
<ContentControl.ContentTemplate>
<DataTemplate>
<TextBlock Text="{local:DynamicBind Name=Tag}" />
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</Grid>
</Page>
```
Expand Down

0 comments on commit e09c648

Please sign in to comment.