title: C# Xml User Control Serialization
body: <p>I serializing my User control and it doesn't work.
  I serializing with XmlWriter. When I serialize my user control I got:</p>
  
  <pre><code>&lt;tmc:WebPage_Control Width=\"600\" Height=\"400\" Canvas.Left=\"251.798397863818\" Canvas.Top=\"122.88785046729\" Panel.ZIndex=\"1\"&gt;
          &lt;Border BorderThickness=\"1,1,1,1\" BorderBrush=\"#FF000000\" Background=\"#FFFFFFFF\"&gt;
              &lt;Grid&gt;
                  &lt;StackPanel Orientation=\"Horizontal\" Height=\"30\" VerticalAlignment=\"Top\"&gt;
                      &lt;StackPanel.Background&gt;
                          &lt;LinearGradientBrush StartPoint=\"0.5,0\" EndPoint=\"0.5,1\"&gt;
                              &lt;LinearGradientBrush.GradientStops&gt;
                                  &lt;GradientStop Color=\"#FFE2E2E2\" Offset=\"0\" /&gt;
                                  &lt;GradientStop Color=\"#FFFFFFFF\" Offset=\"1\" /&gt;
                              &lt;/LinearGradientBrush.GradientStops&gt;
                          &lt;/LinearGradientBrush&gt;
                      &lt;/StackPanel.Background&gt;
                      &lt;Button Width=\"24\" Margin=\"3,3,3,3\" Visibility=\"Collapsed\"&gt;
                          &lt;Image Source=\"pack://application:,,,/app;component/Resources/Specific/Undo.png\" /&gt;
                      &lt;/Button&gt;
                      &lt;Button Width=\"24\" Margin=\"3,3,3,3\" Visibility=\"Collapsed\"&gt;
                          &lt;Image Source=\"pack://application:,,,/app;component/Resources/Specific/Redo.png\" /&gt;
                      &lt;/Button&gt;
                      &lt;Label VerticalContentAlignment=\"Center\"&gt;URL&lt;/Label&gt;
                  &lt;/StackPanel&gt;
                  &lt;WindowsFormsHost x:Name=\"FormHost\" Child=\"{x:Null}\" Margin=\"0,30,0,0\" /&gt;
              &lt;/Grid&gt;
          &lt;/Border&gt;
  &lt;/tmc:WebPage_Control&gt;
  </code></pre>
  
  <p>And I want something like others controls:</p>
  
  <pre><code> &lt;tmc:WebPage_Control Width=\"600\" Height=\"400\" Canvas.Left=\"251.798397863818\" Canvas.Top=\"122.88785046729\" Panel.ZIndex=\"1\"/&gt;
  </code></pre>
  
  <p>When I deserialize my xml output, it not work properly.
  My UserControl have custom dependencyproperty. My user control:                 </p>
  
  <pre><code>&lt;Button Margin="3" Width="24" Visibility="{Binding Path=BackForwardVisibility, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Click="Undo_Click"&gt;
           &lt;Image Source="/app;component/Resources/Specific/Undo.png" /&gt; 
   &lt;/Button&gt;
  </code></pre>
  
  <p>So when I deserialize it not working to change Binding BackForwardVisibility from code because I got:                </p>
  
  <pre><code>&lt;Button Width=\"24\" Margin=\"3,3,3,3\" Visibility=\"Collapsed\"&gt;
       &lt;Image Source=\"pack://application:,,,/app;component/Resources/Specific/Undo.png\" /&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>My Class</p>
  
  <pre><code> public partial class WebPage_Control : UserControl
      {
  
          public static readonly DependencyProperty BFVisibilityProperty =
              DependencyProperty.Register("BackForwardVisibility", typeof(Visibility), typeof(WebPage_Control), new PropertyMetadata(Visibility.Collapsed));
  
  
          public Visibility BackForwardVisibility
          {
              get { return (Visibility)GetValue(BFVisibilityProperty); }
              set { SetValue(BFVisibilityProperty, value); }
          }
  
          public System.Windows.Forms.WebBrowser webBrowser;
  
  
          public WebPage_Control()
          {
              InitializeComponent();
  
              Debug.WriteLine("Initialized!");
  
  
                  System.Windows.Forms.WebBrowser webbr = new System.Windows.Forms.WebBrowser();
              webBrowser = webbr;
              webbr.ScriptErrorsSuppressed = true;
              webbr.Navigated += Webbr_Navigated;
              FormHost.Child = webbr;
          }
  
  
  ...
  </code></pre>