我有一个绑定到Run' Text属性。我绑定到单个类属性。以下是代码和示例:
xaml代码:
<Grid>
<RichTextBox>
<RichTextBox.Document>
<FlowDocument>
<Paragraph >
<Run Text="{Binding TestText,Mode=TwoWay}"></Run>
</Paragraph>
</FlowDocument>
</RichTextBox.Document>
</RichTextBox>
</Grid>
代码背后的代码:
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
this.PropertyChanged += MainWindow_PropertyChanged;
}
private string text = "TestText";
public string TestText
{
get { return text; }
set
{
if (text == value) return;
text = value;
OnPropertyChanged("TestText");
}
}
private void MainWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Console.WriteLine(TestText);
}
#region NotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
当我输入1,2,3,4,5时 我得到了&#34; 5&#34;而不是&#34; 5Te4st3Te2xt1&#34;