Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your wording is a litte inaccurate: it is not the <code>DependencyObjects</code> that are the source or target of a binding, but the <em>properties</em> of the <code>DependencyObjects</code>. A plain property can only be the source in a binding, but a <code>DependencyProperty</code> can act both as a source and as a target. For example in</p> <pre><code>&lt;TextBox Text="{Binding Path=Name}" Name="txtName" /&gt; &lt;Label Content="{Binding ElementName=txtName, Path=Text}" /&gt; </code></pre> <p>the <code>Text</code> property of the <code>TextBox</code> is the target of the binding to some <code>Name</code> property in the <code>DataContext</code>, and at the same time it is the source of the binding to the <code>Content</code> property of the <code>Label</code>. The parameter of a method call is not a property, therefore it cannot be source or target in a binding. In your case the simplest solution is probably to handle the <code>TextBlock.TextChanged</code> event and to call your method from there. Using a <code>ValueConverter</code> as suggested by Martin is also an option.</p> <p><strong>Edit:</strong> Here is a working example that demonstrates the approach using the <code>TextChanged</code> event. It writes the contents of the <code>TextBox</code> to the <code>Console</code> everytime you change something. To bind to the result of your method you could just let the event handler write its result to a property and then bind to that property.</p> <p>MainWindow.xaml:</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;TextBox Name="textBox1" TextChanged="textBox1_TextChanged" /&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>MainWindow.xaml.cs:</p> <pre><code>using System; using System.Windows; using System.Windows.Controls; namespace WpfApplication1 { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { Console.WriteLine(this.textBox1.Text); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThanks for the explanation. I've tried using a TextBox.TextChanged event (as can't find a TextChanged event for a TextBlock), but it doesn't fire when the text changes. I'm still trying Value Converters as an option as well, but my Convert class throws an exception every time it's called. At least I'm learning a lot about WPF in the process of trying to solve this...! I understand about it being the properties of DependencyObjects that are bound, but where I'm getting stuck is in trying to use the process outlined on this page http://msdn.microsoft.com/en-us/library/aa348824.aspx
      singulars
    2. COI've added the method GetThisRelationshipEntities(String relationshipName) as a UserControl resource, but in order to bind a DependencyObject's property to the result of the method I have to of course pass in a String value to the method. But to use a TextBlock.Text value as the parameter, it looks like you have to do something like <TextBlock Binding Source="{StaticResource getThisRelationshipEntities}" Path="MethodParameters[0]" />
      singulars
    3. COThat was what I meant by my TextBlock.Text property needing to be both a target & a source, because it is a target with Text="{Binding Path=Relationship.Name" but also a "source" for the method parameter. I'll keep trying the different things you suggested however & will let you know if I have any success. Apologies for all the comments but I couldn't post everything in one go!
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload