Skip to content

Commit 4332f85

Browse files
michael-hawkerArlodotexe
authored andcommitted
Add sample for FrameworkElementExtensions.Ancestor/Type
1 parent 8460b35 commit 4332f85

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Page x:Class="ExtensionsExperiment.Samples.FrameworkElementAncestorSample"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:local="using:ExtensionsExperiment.Samples"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:ui="using:CommunityToolkit.WinUI"
8+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
9+
mc:Ignorable="d">
10+
11+
<StackPanel Padding="16"
12+
Spacing="{x:Bind ValueSlider.Value, Mode=OneWay}">
13+
<Slider x:Name="ValueSlider"
14+
Maximum="16"
15+
Minimum="4"
16+
StepFrequency="4"
17+
Value="8" />
18+
<TextBlock Text="This is some text in a StackPanel with Spacing:" />
19+
<TextBlock ui:FrameworkElementExtensions.AncestorType="StackPanel"
20+
Text="{Binding (ui:FrameworkElementExtensions.Ancestor).Spacing, RelativeSource={RelativeSource Self}}" />
21+
</StackPanel>
22+
</Page>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace ExtensionsExperiment.Samples;
6+
7+
/// <summary>
8+
/// An empty page that can be used on its own or navigated to within a Frame.
9+
/// </summary>
10+
[ToolkitSample(id: nameof(FrameworkElementAncestorSample), nameof(FrameworkElementAncestorSample), description: $"A sample for showing how to use the FrameworkElementExtensions.Ancestor attached property.")]
11+
public sealed partial class FrameworkElementAncestorSample : Page
12+
{
13+
public FrameworkElementAncestorSample()
14+
{
15+
this.InitializeComponent();
16+
}
17+
}

components/Extensions/samples/FrameworkElementExtensions.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ The `AncestorType` attached property will walk the visual tree from the attached
102102

103103
Here is an example of how this can be used:
104104

105-
```xaml
106-
<Button
107-
ui:FrameworkElementExtensions.AncestorType="Grid"
108-
Visibility="{Binding (ui:FrameworkElementExtensions.Ancestor).Visibility,RelativeSource={RelativeSource Self}}"/>
109-
```
105+
> [!SAMPLE FrameworkElementAncestorSample]
106+
107+
While this example is trivial, it shows you how to properly setup and bind to the parent element's property, in this case `Spacing`.
110108

111109
## Cursor
112110

0 commit comments

Comments
 (0)