How can we improve the Windows dev platform?

Ancestor binding missing

Currently the RelativeSourceMode only supports None, TemplatedParent and Self.

Would be really helpful to have FindAncestor API added, just like in Silverlight 5 and WPF.

74 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Justin LiuJustin Liu shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • MartinMartin commented  ·   ·  Flag as inappropriate

        Useage Scenarios of RelativeSource:
        (This could also be achieved with ElementName, but requires setting a Name for the TextBox. With the AncetoryType Binding we can just copy/paste the KeyBinding, so we prefer the AncetoryType solution )
        <TextBox KeyboardNavigation.TabIndex="0" MaxLength="12" Text="{Binding Path=OrderNo,UpdateSourceTrigger=PropertyChanged}">
        <TextBox.InputBindings>
        <KeyBinding Key="Enter" Command="{Binding Path=StartACommand}" CommandParameter="{Binding Path=Text,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type TextBox}}}"/>
        </TextBox.InputBindings>
        </TextBox>

        An other example where we use AncestorType:

        <ListView ItemsSource="{Binding Path=List,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
        <ListView.ItemTemplate>
        <DataTemplate>
        <DockPanel>
        <Button Content="AText" Command="{Binding DataContext.RemoveCommand,RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
        CommandParameter="{Binding Path=.}" />
        </DockPanel>
        </DataTemplate>
        </ListView.ItemTemplate>
        </ListView>

      Feedback and Knowledge Base