2010-11-07 123 views
0

我是WPF中的新手。我需要使TwoWay和OneWayToSource绑定到字符串变量。我想使用Extended WPF Toolkit中的richtextbox,因为我认为这是简单的方法。扩展WPF工具包 - richtextbox的绑定文本

所以我尝试使用richtebox从这个库中的XAML,代码是在这里:

<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> 

在后面的代码,我有这样的代码:

private string _rpText = string.Empty; 

    public ChatWindow(PokecCommands pokecCmd) 
    { 
     rtbRpText.DataContext = _rpText; 
    } 

问题是,如果我写的东西richtextbox,变量_rpText仍然是空的,哪里可以解决问题?

回答

1

您是否尝试过输入内容然后将焦点从RichTextBox移开?我怀疑你的财产将会被更新。如果您想在输入时更新房产,则需要:

Text="{Binding _rpText, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" 
+0

它不工作,我的RichTextBox的属性文本绑定到变量字符串,没有串财产,你的解决方案的工作只有当我绑定到字符串属性实现INotifyPropertyChanged的类。 – Joe 2010-11-07 17:10:35

+2

如果没有财产变更通知,您会如何预计它会起作用? – 2010-11-07 18:02:20

+0

Sory,我不知道。所以这个接口是一个条件。 – Joe 2010-11-07 18:10:11

0

肯特是正确的。您的属性必须禁止INotifyPropertyChanged接口使数据绑定在WPF/Silverlight中正常工作。

documentation介绍如何将属性绑定到RichTextBox的:

相关问题