title: How to access member controls in a WPF derived UserControl
body: <p>I have a Windows phone based control and want to derive other Windows phone <code>UserControl</code>s from it.</p>
  
  <p>When I put the derivation code in and try to access other controls from the derived class, I get an error:</p>
  
  <pre><code>The name 'LocationConsent_CheckBox' does not exist in the current context
  &lt;path&gt;\project\RML\RML\CtrlLocServ.xaml.cs
  </code></pre>
  
  <p>Base <code>UserControl</code> xaml:</p>
  
  <pre><code>&lt;UserControl x:Class="RML.CtrlBase"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               mc:Ignorable="d" 
               d:DesignHeight="300" d:DesignWidth="300"&gt;
      &lt;Grid x:Name="LayoutRoot"&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Base <code>UserControl</code> code behind:</p>
  
  <pre><code>namespace RML
  {
      public partial class CtrlBase : UserControl
      {
          public CtrlBase()
          {
                      InitializeComponent();
                      LayoutRoot.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent);
          }
      }
  }
  </code></pre>
  
  <p>Derived <code>UserControl</code> xaml:
  (Notice I have changed the name of the grid to LayoutRoot2 instead of LayoutRoot.)</p>
  
  <pre><code>&lt;src:CtrlBase x:Class="CtrlLocServ"
               xmlns:src="clr-namespace:RML"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               mc:Ignorable="d" 
               d:DesignHeight="300" d:DesignWidth="300"&gt;
      &lt;Grid x:Name="LayoutRoot2"&gt;
          &lt;StackPanel&gt;
              &lt;CheckBox x:Name="LocationConsent_CheckBox" /&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/src:CtrlBase&gt;
  </code></pre>
  
  <p>Derived <code>UserControl</code>, code behind:</p>
  
  <pre><code>namespace RML
  {
      public partial class CtrlLocServ : CtrlBase
      {
          public CtrlLocServ()
          {
              InitializeComponent();
              LocationConsent_CheckBox.IsChecked = false;
          }
      }
  }
  </code></pre>
  
  <p>This still gives me the above error though.</p>
  
  <p>Here is the generated file:</p>
  
  <pre><code>#pragma checksum "..\..\CtrlLocationService.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "D56B477B354FB03C45E5F49343F67196"
  //------------------------------------------------------------------------------
  // &lt;auto-generated&gt;
  //     This code was generated by a tool.
  //     Runtime Version:4.0.30319.18063
  //
  //     Changes to this file may cause incorrect behavior and will be lost if
  //     the code is regenerated.
  // &lt;/auto-generated&gt;
  //------------------------------------------------------------------------------
  
  using System;
  using System.Diagnostics;
  using System.Windows;
  using System.Windows.Automation;
  using System.Windows.Controls;
  using System.Windows.Controls.Primitives;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Ink;
  using System.Windows.Input;
  using System.Windows.Markup;
  using System.Windows.Media;
  using System.Windows.Media.Animation;
  using System.Windows.Media.Effects;
  using System.Windows.Media.Imaging;
  using System.Windows.Media.Media3D;
  using System.Windows.Media.TextFormatting;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.Windows.Shell;
  namespace RML {
  
  
  /// &lt;summary&gt;
  /// CtrlLocationService
  /// &lt;/summary&gt;
  public partial class CtrlLocationService : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
  
      private bool _contentLoaded;
  
      /// &lt;summary&gt;
      /// InitializeComponent
      /// &lt;/summary&gt;
      [System.Diagnostics.DebuggerNonUserCodeAttribute()]
      [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
      public void InitializeComponent() {
          if (_contentLoaded) {
              return;
          }
          _contentLoaded = true;
          System.Uri resourceLocater = new System.Uri("/RML;component/ctrllocationservice.xaml", System.UriKind.Relative);
  
          #line 1 "..\..\CtrlLocationService.xaml"
          System.Windows.Application.LoadComponent(this, resourceLocater);
  
          #line default
          #line hidden
      }
  
          [System.Diagnostics.DebuggerNonUserCodeAttribute()]
          [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
          [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
          [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
          [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
          [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
          void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
              this._contentLoaded = true;
          }
      }
  }
  </code></pre>
  
  <p>Suggestions would be much appreciated.</p>