Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Adjust MarkupExtension sample #18870

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading