Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While your above (self-answered) answer seems to fix the problem, I can't help but think this is a problem domain issue. I have a hard time thinking <em>why</em> you'd want to bind directly like that in the first place, especially since it gives you less control over what happens with the data.</p> <p>Take the following:</p> <pre><code>&lt;UserControl x:Class="SilverlightApplication1.XText" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="UserControl" d:DesignHeight="300" d:DesignWidth="400"&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;TextBox x:Name="Text" Text="{Binding Path=Value, ElementName=UserControl, Mode=TwoWay}"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Then in the codebehind:</p> <pre><code>public partial class XText { public static DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(string), typeof(XText), new FrameworkPropertyMetadata(null) ); public string Value { get { return ((string)(base.GetValue(XText.ValueProperty))); } set { base.SetValue(XText.ValueProperty, value); } } ... } </code></pre> <p>Then, when you're ready to use it:</p> <pre><code>&lt;uc:XText Value="{Binding Path=MyObject, Mode=TwoWay}" /&gt; </code></pre> <p>Yes, it's more code, but it gives you much more control over what happens with <code>Value</code> inside of your <code>UserControl</code>, and makes working with this code much much simpler in the future.</p> <p>Thoughts?</p> <p>-Doug</p> <p>EDIT: fixed a couple typos.</p>
 

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