Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight for windows phone 7 custom textbox usercontrol text property returning null
    primarykey
    data
    text
    <p>I am making an application for Windows Phone 7, and i ran into the following problem: When I make a usercontrol that contains a textbox, and make a DependencyProperty to be able to databind it, the property for accessing it returns null, and when i'm triing to set the text to something, it doesn't do it. I read <a href="https://stackoverflow.com/questions/5043873/windows-phone-7-textblock-text-binding-to-viewmodel-not-returning-anythinig">Here</a> that "You need to call NotifyPropertyChanged() in your setters for the items you wish to bind to.", but I don't know how to do that. There is the INotifyPropertyChanged interface, but i dont think I need that, and I didn't find any clues how to write it, if I had to write it.</p> <p>Here's my usercontrol:</p> <pre><code> &lt;Grid VerticalAlignment="Stretch"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="1*"&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition Width="5.18*"&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="1*"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="1*"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0" Text="{Binding Tag}" Foreground="Black" Margin="10,0,0,0" Style="{StaticResource MenuTextStyle}" TextWrapping="Wrap"/&gt; &lt;Image Source="../Resources/Graphics/sign_arrow_black.png" Margin="0,15,0,0" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" Height="30"&gt; &lt;/Image&gt; &lt;TextBox x:Name="ContentBox" Style="{StaticResource TextBoxStyle}" VerticalAlignment="Top" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Grid.Column="1" Grid.Row="1" Padding="0,0,0,0" Margin="0,0,0,0" BorderThickness="0" IsReadOnly="{Binding IsReadOnly}" Text="{Binding TextContent}"&gt; &lt;/TextBox&gt; &lt;/Grid&gt; </code></pre> <p>And here's the DependencyProperty: (EDIT: Reformatted)</p> <pre><code> public static readonly DependencyProperty TextContentProperty = DependencyProperty.Register("TextContent", typeof(string), typeof(LargeTextBox), new PropertyMetadata(default(string))); public string TextContent { get { return (string)GetValue(TextContentProperty); } set { SetValue(TextContentProperty, value);} } </code></pre> <p>PS: I know about styles, and templates, but since i have the same problem with more complex controls, it's not an option.</p> <p>EDIT: I worked on the problem, and solved the "text not showing"-issue, and i could get the textboxt's text put on another control, but when i'm databinding it, it still doesn't work. I achieved this by writing the ValueChangedCallback:</p> <pre><code>private static void OnTextPropertyChanged(object sender, DependencyPropertyChangedEventArgs e) { LargeTextBox box = (LargeTextBox)sender; box.ContentBox.Text = box.Text; if (box.TextChanged != null) box.TextChanged(box, new DependencyPropertyChangedEventArgs()); } </code></pre> <p>And the textbox's TextChanged eventhandler:</p> <pre><code> private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { Text = ContentBox.Text; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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