I have a SilverlightPage eg MainPage. This page contains a GoXam-Diagram. In the xaml of the MainPage the diagram and the node-template is defined.

How can I use DataBinding in a node to the MainPage?

For example:

Thanks in advance!


I think you want to use “{Binding ElementName=MainPage, Path=TestProperty, Mode=TwoWay}”.

I tried it your way, but it does not work.

What do I do wrong?

That´s part of my MainPage.xaml:

<br /><DataTemplate x:Key="NodeTemplate"> <br /> <Border BorderThickness="1" BorderBrush="Black" Width="Auto" Height="Auto"> <br /> <StackPanel> <br /> <TextBlock Text="{Binding Path=Data.Name, Mode=TwoWay}" go:Part.TextEditable="True" /> <br /> <TextBlock Text="{Binding ElementName=MainPage, Path=TestProperty, Mode=TwoWay}" <br /> MinHeight="15" MinWidth="20" go:Part.TextEditable="True"/> <br /> </StackPanel> <br /> </Border> <br /></DataTemplate> <br />

That´s my MainPage.xaml.cs:

<br />public partial class MainPage : UserControl, INotifyPropertyChanged <br />{ <br /> public event PropertyChangedEventHandler PropertyChanged; <br /> <br /> private string _TestProperty; <br /> public string TestProperty <br /> { <br /> get <br /> { <br /> return _TestProperty; <br /> } <br /> set <br /> { <br /> _TestProperty = value; <br /> NotifyPropertyChanged("TestProperty"); <br /> } <br /> } <br /> <br /> private void NotifyPropertyChanged(String info) <br /> { <br /> if (PropertyChanged != null) <br /> { <br /> PropertyChanged(this, new PropertyChangedEventArgs(info)); <br /> } <br /> } <br /> <br /> public MainPage() <br /> { <br /> TestProperty = "DataBindingTest"; <br /> InitializeComponent(); <br /> //... <br /> } <br />} <br />

You need to provide the name of the element that you want to bind to as the ElementName property of the Binding. Apparently that’s not “MainPage”, because that’s the name of your class, not the name of the XAML instance of the MainPage.

There are a bunch of examples of using “{Binding ElementName=… …}” in the Demo.

You also want to read the Microsoft documentation for using Binding.ElementName.

In WPF, we use the following :

{Binding RelativeSource={RelativeSource Mode=FindAncestor,    
               AncestorType={x:Type v6QEditor:QLargeTreeControl}},

Maybe you can use

{Binding RelativeSource={RelativeSource Mode=FindAncestor,    
               AncestorType={x:Type Window}},


That’s good idea, but unfortunately Silverlight 4 does not support RelativeSourceMode.FindAncestor.