This project is read-only.

[Version 1.3] Custom Document and Saving

Jul 22, 2010 at 6:11 PM

I have created the following custom document after reading the restyling tutorial:

    public partial class MyContent : DocumentContent
    {
        public String CustomFilter
        {
            get { return (String)GetValue(CustomFilterProperty); }
            set { SetValue(CustomFilterProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CustomFilter.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CustomFilterProperty =
            DependencyProperty.Register("CustomFilter", typeof(String), typeof(MyContent), new UIPropertyMetadata(String.Empty));


        public MyContent()
        {
            InitializeComponent();
        }

        public override void SaveLayout(System.Xml.XmlWriter storeWriter)
        {
            base.SaveLayout(storeWriter);

            storeWriter.WriteAttributeString("CustomFilter", CustomFilter);
        }

        public override void RestoreLayout(System.Xml.XmlElement contentElement)
        {
            base.RestoreLayout(contentElement);

            if (contentElement.HasAttribute("CustomFilter"))
                CustomFilter = contentElement.GetAttribute("CustomFilter");
        }
    }
I have some XAML which simply displays the CustomFilter text in the document.
When I save the layout I can see my custom SaveLayout code being called, and the resulting Xml contains whatever value I had in CustomFilter.
The problem comes when I try to restore the layout. I end up in the callback event handler with none of my custom information. My custom RestoreLayout code is never called.
Can someone shed some light on this please?
Thanks