Reputation: 91
I am newbie in WPF. I need make TwoWay and OneWayToSource bind to string variable. I want use richtextbox from Extended WPF Toolkit ,because I think it is the easy way.
So I try use richtebox from this library in xaml, code is here:
<Window x:Class="PokecMessanger.ChatWindow"
xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChatWindow" Height="429" Width="924">
///...
<extToolkit:RichTextBox Name="rtbRpText" Text="{Binding _rpText, Mode=OneWayToSource}" Grid.Column="0"></extToolkit:RichTextBox>
In code behind, I have this code:
private string _rpText = string.Empty;
public ChatWindow(PokecCommands pokecCmd)
{
rtbRpText.DataContext = _rpText;
}
Problem is, if I wrote something in richtextbox, variable _rpText is still empty, where can be problem?
Upvotes: 0
Views: 4728
Reputation: 178630
Have you tried typing something and then shifting focus off the RichTextBox
? I suspect your property will then be updated. If you want to update the property as you type, you'll need:
Text="{Binding _rpText, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
Upvotes: 2
Reputation:
Kent is correct. Your properties MUST impement the INotifyPropertyChanged interface for data binding to work properly in WPF/Silverlight.
The documentation explains how to bind your property to the RichTextBox:
Upvotes: 0