Skip to content

Commit

Permalink
Merge pull request #1209 from unoplatform/dev/ks/docs-ancestorBindings
Browse files Browse the repository at this point in the history
docs: AncestorBindings- fixing example code
  • Loading branch information
Kunal22shah authored Jul 30, 2024
2 parents ce4a857 + ad676ad commit 25a43ed
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions doc/helpers/ancestor-itemscontrol-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,30 @@ xmlns:utu="using:Uno.Toolkit.UI"
...

<!-- Assuming the DataContext is set to an instance of ExampleModel -->
<Border Tag="From Border">
<ListView ItemsSource="{Binding Items}" Tag="From ListView">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock>Current item DataContext: <Run Text="{Binding}" /></TextBlock>
<TextBlock>Current parent(ExampleModel) DataContext:
<Run Text="{utu:AncestorBinding AncestorType=ListView, Path=DataContext.SomeText}" />
</TextBlock>

<TextBlock>Accessing property of a parent ListView:
<Run Text="{utu:AncestorBinding AncestorType=ListView, Path=Tag}" />
</TextBlock>
<TextBlock>Accessing property of a parent Border:
<Run Text="{utu:AncestorBinding AncestorType=Border, Path=Tag}" />
</TextBlock>
<StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Border>
<Page Tag="From Page">
<StackPanel>
<TextBlock Text="From DataContext:" />
<TextBlock Text="{Binding SomeText}" />

<ListView ItemsSource="{Binding Items}" Tag="From ListView">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="Current item DataContext:" />
<TextBlock FontWeight="Bold" Text="{Binding}" />

<TextBlock Text="Current parent (ExampleModel) DataContext:" />
<TextBlock FontWeight="Bold" Text="{utu:ItemsControlBinding Path=DataContext.SomeText}" />

<TextBlock Text="Accessing property of a parent ListView:" />
<TextBlock FontWeight="Bold" Text="{utu:ItemsControlBinding Path=Tag}" />

<TextBlock Text="Accessing property of a Page:" />
<TextBlock FontWeight="Bold" Text="{utu:AncestorBinding AncestorType=Page, Path=Tag}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>
```

0 comments on commit 25a43ed

Please sign in to comment.