4
タイトルに既にあるように、私はDependencyPropertyでデータバインディングを使用する際に問題があります。私はHTMLBoxというクラスを持っている:WPF依存プロパティ - データバインディングが機能しません。
public class HTMLBox : RichTextBox
{
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(HTMLBox));
public string Text
{
get
{
return GetValue(TextProperty) as string;
}
set
{
Console.WriteLine("Setter...");
SetValue(TextProperty, value);
}
}
public HTMLBox()
{
// Create a FlowDocument
FlowDocument mcFlowDoc = new FlowDocument();
// Create a paragraph with text
Paragraph para = new Paragraph();
para.Inlines.Add(new Bold(new Run(Text)));
// Add the paragraph to blocks of paragraph
mcFlowDoc.Blocks.Add(para);
this.Document = mcFlowDoc;
}
}
私はコンストラクタでテキストプロパティを読んで、その文字列がプロパティにバインドされたとき、それはテキストとして表示されなければなりません。しかし、私はいくつかのデータをxamlのTextプロパティにバインドしても、 "Setter ..."は表示されません。 - Textプロパティが設定されているときに表示されるべきメッセージ。
<local:HTMLBox Text="{Binding Text}"
Width="{Binding Width}"
AcceptsReturn="True"
Height="{Binding Height}" />
私はテキストをテキストボックスするHTMLBoxを変更した場合は正しく表示されますので間違いは私のHTMLBoxクラスでsomwhereおそらくです。私は間違って何をしていますか?
ありがとうございました。変更イベントハンドラを使用して問題を解決しました。ここで学ぶべきことがたくさんあるようです:) – BoltzmannBrain