Synchronizing control properties with the parent control properties in WPF

Sometimes you need synchronize the properties of a control with the properties of the parent control, in order to accomplish this you can use a binding by element name. In the example below you can see how to make the size of a control equal to its parent control by using binding:

 

<Canvas>

  <DockPanel

      Width="{Binding RelativeSource=

                {RelativeSource FindAncestor,

                AncestorType={x:Type Canvas}},

                Path=ActualWidth}"

      Height="{Binding RelativeSource=

                {RelativeSource FindAncestor,

                AncestorType={x:Type Canvas}},

                Path=ActualHeight}">

  </DockPanel>

</Canvas>

Published Tuesday, October 23, 2007 1:30 PM by marianor
Filed under:

Comments

No Comments