Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have found a solution that doesn't require you to give a name to the base control. When I defined a name for the base UserControl it was creating issues for me when I was adding multiple instances to my Grid, since they were defined as the same name.</p> <p>This is a combination of my first answer and Doug's answer. Note the UserControl lacks the name property and the TextBox has no Binding declared in the XAML</p> <p><strong>XAML</strong></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" d:DesignHeight="300" d:DesignWidth="400"&gt; &lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;TextBox x:Name="MyText"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p><strong>CodeBehind</strong></p> <pre><code>public partial class XText { public XText() { InitializeComponent(); MyText.SetBinding(TextBox.TextProperty, new Binding() { Source = this, Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay }); } public static DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof(string), typeof(XText), new PropertyMetadata(null) ); public string Value { get { return ((string)(GetValue(ValueProperty))); } set { SetValue(ValueProperty, value); } } ... } </code></pre> <p>When you are ready to use it do the following</p> <pre><code>&lt;uc:XText Value="{Binding Path=MyObject, Mode=TwoWay}" /&gt; </code></pre>
 

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