Skip to content

Commit

Permalink
Merge pull request #18870 from unoplatform/dev/jela/update-binding
Browse files Browse the repository at this point in the history
docs: Adjust MarkupExtension sample
  • Loading branch information
jeromelaban authored Nov 21, 2024
2 parents 2f48f5f + 1523d19 commit 4f651d2
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 4f651d2

Please sign in to comment.