Skip to content

Commit

Permalink
Merge pull request #18877 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.5/pr-18870

docs: Adjust MarkupExtension sample (backport #18870)
  • Loading branch information
jeromelaban authored Nov 21, 2024
2 parents 81e7501 + e09c648 commit a71ab98
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 a71ab98

Please sign in to comment.