Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Bug] Two (Closely Related) RelativeSource Binding Issues #8450

@legistek

Description

@legistek

Description

(1) RelativeSource bindings using the FindAncestorBindingContext mode do not get re-applied when the BindingContext of any of the ancestors changes without re-parenting. This may or may not be the problem @IoTFier was having but investigating his issue led to my discovery of this problem.

(2) I misinterpreted the WPF documentation for AncestorLevel when reproducing it for XF. The correct behavior is that an AncestorLevel of n skips n-1 instances of the AncestorType in the tree. The current behavior is that it skips n-1 levels (regardless of type) in the visual tree.

Steps to Reproduce

For (1), simply create a binding using the FindAncestorBindingContext RelativeSource mode and change the BindingContext of the source during the lifecycle of the app. The bound target will never update.

For (2):

<StackLayout StyleId="stack1">
     <StackLayout StyleId="stack2">
          <Grid>
               <Label Text="{Binding StyleId, Source={RelativeSource AncestorType={x:Type StackLayout}, AncestorLevel=2}}"/>
          </Grid>
     </StackLayout>
</StackLayout>

Expected:
Label text = stack1

Actual:
Label text = stack2

Resolution

I've coded a fix and more robust unit tests here. If there's no objection will I submit a PR imminently. cc: @StephaneDelcroix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions