I'm currently trying to convert a wpf form with several textboxes on it to RichTextBoxes to allow for better editing functionality. The original textboxes were all linked to an underlying storage class using databinding to a data context upon navigation to the page.
public class Storage
{
public String IntroFormText { get; set; }
public String MainFormText { get; set; }
}
public partial class DataEntryPage : BasePage
{
private Storage _storage { get; set; }
public override NavigatingTo(object data, object savedState)
{
DataContext = _storage;
}
}
Originally, the bindings in the text box would have simply gone through and linked to the Storage class via the data context like so.
<TextBox
Name="IntroText"
Text="{Binding IntroFormText}
SpellCheck.IsEnabled="True" />
This would then link via the data binding to _storage.IntroFormText automatically. To allow for two way data bindings in the RichTextBoxes, a custom implementation based on the ideas in this article was used. The problems come when trying to link the data bindings to the properties in the Storage class. With the RichTextBoxes the following declaration is used:
<Utils:BindableRichTextBox
x:Name="IntroductionText"
Document="{Binding {Path=IntroFormText, ElementName=dataEntryPage, Mode=TwoWay, Converter={StaticResource StringToXamlConverter}}"
SpellCheck.IsEnabled="True" />
The idea is then to overload the getters and setters for the relevant property, adding the following lines to the DataEntryPage class.
private static readonly DependencyProperty introProperty = DependencyProperty.Register("IntroFormText", typeof(string), typeof(Storage));
public string IntroFormText
{
get { return (string) GetValue(DocumentProperty); }
set { SetValue(DocumentProperty, value); }
}
The problem I have here though, is that the property it needs to be linked with, resides in the Storage class, and NOT in the DataEntryPage class. Is there any way to get the DependencyProperty to effectively bind to the Storage class properties (as the TextBox does automatically), or am I going to have to write some kind of hacked together replacement for this behavior? I guess I need to overload the getters / setters for the Storage.Properties class inside of the DataEntryPage class to allow it to point at the DependencyProperty properly?
Due to the nature of the system, removing the data context bindings system isn't really an option unfortunately (plus I don't have permission to alter the design that heavily!). Hopefully though, this might make sense to someone who's run into the issue before!