Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Bind to element in parent window

Tags:

c#

wpf

xaml

I'm trying to bind element's property in a child control to an element's property ina parent window, it doesn't work..

Here is png of what I'm trying to do: enter image description here

Here is the xaml that doesn't work:

CurrentDate="{Binding ElementName=TimeBar, Path=SelectionStart,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" 

Thanks.

like image 537
Slime recipe Avatar asked Dec 03 '13 07:12

Slime recipe


1 Answers

create a dependency property in your usercontrol and then bind to it in your window

something like that: DependencyProperty implementations you can find all around here on stackoverflow

<YourUsercontrol x:Name="uc">
  <YourSomeControl CurrentDate="{Binding ElementName=uc, Path=MyDp}"/>
 </YourUsercontrol>

xaml window

 <Window>
   <ElementInParent x:Name="eip" />
   <YourUsercontrol MyDp="{Binding ElementName=eip, Path=PropertyFromElementInParent}"/>
like image 142
blindmeis Avatar answered Oct 06 '22 04:10

blindmeis