Set parent control's property with change in child control's property value in XAML (Using AncestorType binding)

In XAML, one can set parent's property from the change in a property of child control. To do so we can use AncestorType binding for the child control.

Consider an example we have a StackPanel having a TextBox. Which ever color user enters in the textbox must be reflected in the StackPanel's Background.

XAML

<StackPanel Orientation="Vertical" x:Name="stk">             <StackPanel Orientation="Horizontal">                 <TextBlock Text="Enter Color:"></TextBlock>   <TextBox x:Name="colorName" Width="150" BorderBrush="Brown"      Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,         AncestorType={x:Type StackPanel}}, Path=Background,Mode=OneWayToSource}">   </TextBox><TextBox Text="Color Format = ARGB"></TextBox>             </StackPanel> </StackPanel>

Output




as we are seeing in the output whichever color we are inserting in the text box is being set as background color of the stackpanel.

1 comment:

  1. Hub Of Computer Tricks And Programming: Set Parent Control'S Property With Change In Child Control'S Property Value In Xaml (Using Ancestortype Binding) >>>>> Download Now

    >>>>> Download Full

    Hub Of Computer Tricks And Programming: Set Parent Control'S Property With Change In Child Control'S Property Value In Xaml (Using Ancestortype Binding) >>>>> Download LINK

    >>>>> Download Now

    Hub Of Computer Tricks And Programming: Set Parent Control'S Property With Change In Child Control'S Property Value In Xaml (Using Ancestortype Binding) >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete