Dependency property on custom user control
I have a big issue here. Here's the thing:
I have a custom control which contains a RichTextBox. In this rich text box i introduce hyperlinks and textblocks.
In the user Control I have Property named Designer which returns the serialized flow document from the richtextbox contained in my usercontrol.
public string Designer
{
get
{
return XamlWriter.Save(linkRtb.Document);
}
set
{
var stringReader = new StringReader(value);
开发者_开发问答 var xmlTextReader = new XmlTextReader(stringReader);
linkRtb.Document = (FlowDocument)XamlReader.Load(xmlTextReader);
OnPropertyChanged("Designer");
}
}
Binding anything to this property works. But what i want to do is to bind this property to something that i have in code behind. The problem is that if I make Designer a dependency property the binding doesn't work and i have no clue why.
The binding that i want to do looks like this:
Designer="{Binding Source=CodeBehindClass, Path=CodeBehindVariable, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
From what i have read i understood that you cannot add any logic to the get and set for the dependency property.
Correct, use the PropertyChangedCallback
in the metadata upon DP registration instead.
精彩评论