title: Silverlight for Windows Phone: BindingExpression path error with user control - Property not found
body: <p>Just hit a very odd issue with databinding which I cannot seem to get to the bottom of:</p>
  <p>Scenario
  An MVVM View model data bound to a parent form with two properties</p>
  <pre><code>    public RelayCommand ClearFilteredCategories { get; private set; }
  
      /// &lt;summary&gt;
      /// The &lt;see cref=&quot;ClearFilterText&quot; /&gt; property's name.
      /// &lt;/summary&gt;
      public const string ClearFilterTextPropertyName = &quot;ClearFilterText&quot;;
  
      private string _clearFilterText = &quot;Clear Filter&quot;;
  
      /// &lt;summary&gt;
      /// Sets and gets the ClearFilterText property.
      /// Changes to that property's value raise the PropertyChanged event. 
      /// &lt;/summary&gt;
      public string ClearFilterText
      {
          get
          {
              return _clearFilterText;
          }
  
          set
          {
              if (_clearFilterText == value)
              {
                  return;
              }
  
              _clearFilterText = value;
              RaisePropertyChanged(ClearFilterTextPropertyName);
          }
      }
  </code></pre>
  <p>Then I have a User control with Two dependency Properties, thus:</p>
  <pre><code>    public partial class ClearFilterButton : UserControl
  {
      public ClearFilterButton()
      {
          // Required to initialize variables
          InitializeComponent();
      }
  
      public string ClearFilterString
      {
          get { return (string)GetValue(ClearFilterStringProperty); }
          set { SetValue(ClearFilterStringProperty, value); }
      }
  
      public RelayCommand ClearFilterAction
      {
          get { return (RelayCommand)GetValue(ClearFilterActionProperty); }
          set { SetValue(ClearFilterActionProperty, value); }
      }
  
      public static readonly DependencyProperty ClearFilterStringProperty =
          DependencyProperty.Register(&quot;ClearFilterString&quot;, typeof(string), typeof(ClearFilterButton), new PropertyMetadata(&quot;&quot;, ClearFilterString_PropertyChangedCallback));
  
      public static readonly DependencyProperty ClearFilterActionProperty =
          DependencyProperty.Register(&quot;ClearFilterAction&quot;, typeof(RelayCommand), typeof(ClearFilterButton), new PropertyMetadata(null, ClearFilterAction_PropertyChangedCallback));
  
      private static void ClearFilterString_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          //empty
      }
  
      private static void ClearFilterAction_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          //empty
      }
  }
  </code></pre>
  <p>and User Control XAML:</p>
  <pre><code>&lt;UserControl
  xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
  xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
  xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
  xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
  xmlns:i=&quot;clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity&quot; xmlns:GalaSoft_MvvmLight_Command=&quot;clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71&quot;
  mc:Ignorable=&quot;d&quot;
  x:Class=&quot;ATTCookBook.ClearFilterButton&quot;
  d:DesignWidth=&quot;75&quot; d:DesignHeight=&quot;75&quot;
  DataContext=&quot;{Binding RelativeSource={RelativeSource Self}}&quot;&gt;
  
  &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;Transparent&quot;&gt;
      &lt;Button HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot; BorderBrush=&quot;{x:Null}&quot; Width=&quot;75&quot; Height=&quot;75&quot;&gt;
          &lt;i:Interaction.Triggers&gt;
              &lt;i:EventTrigger EventName=&quot;Click&quot;&gt;
                  &lt;GalaSoft_MvvmLight_Command:EventToCommand Command=&quot;{Binding ClearFilterAction, Mode=TwoWay}&quot;/&gt;
              &lt;/i:EventTrigger&gt;
          &lt;/i:Interaction.Triggers&gt;
          &lt;Button.Background&gt;
              &lt;ImageBrush Stretch=&quot;UniformToFill&quot; ImageSource=&quot;/icons/appbar.refresh.rest.png&quot;/&gt;
          &lt;/Button.Background&gt;
      &lt;/Button&gt;
      &lt;TextBlock HorizontalAlignment=&quot;Center&quot; Margin=&quot;0,0,0,8&quot; TextWrapping=&quot;Wrap&quot; Text=&quot;{Binding ClearFilterString, Mode=TwoWay}&quot; VerticalAlignment=&quot;Bottom&quot; FontSize=&quot;13.333&quot; Height=&quot;18&quot; Width=&quot;0&quot; d:LayoutOverrides=&quot;VerticalAlignment&quot;/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Now when I add this User Control to the Main Page and databind the two View Model Properties through to the User control it gets very weird:</p>
  <pre><code>&lt;local:ClearFilterButton Height=&quot;Auto&quot; Width=&quot;Auto&quot; ClearFilterAction=&quot;{Binding ClearFilteredCategories, Mode=TwoWay}&quot; ClearFilterString=&quot;{Binding ClearFilterText, Mode=TwoWay}&quot;/&gt;
  </code></pre>
  <p>Because although the Databinding statements above seem fine, the Binding errors with:</p>
  <blockquote>
  <p>System.Windows.Data Error: BindingExpression path error: 'ClearFilteredCategories' property not found on 'ATTCookBook.ClearFilterButton' 'ATTCookBook.ClearFilterButton' (HashCode=126600431). BindingExpression: Path='ClearFilteredCategories' DataItem='ATTCookBook.ClearFilterButton' (HashCode=126600431); target element is 'ATTCookBook.ClearFilterButton' (Name=''); target property is 'ClearFilterAction' (type 'GalaSoft.MvvmLight.Command.RelayCommand')..</p>
  <p>System.Windows.Data Error: BindingExpression path error: 'ClearFilterText' property not found on 'ATTCookBook.ClearFilterButton' 'ATTCookBook.ClearFilterButton' (HashCode=126600431). BindingExpression: Path='ClearFilterText' DataItem='ATTCookBook.ClearFilterButton' (HashCode=126600431); target element is 'ATTCookBook.ClearFilterButton' (Name=''); target property is 'ClearFilterString' (type 'System.String')..</p>
  </blockquote>
  <p>Which seems to indicate the View Model is trying to find the parent properties in the child user control?
  I do not understand why this could be because I have set a Relative Data Context within the child user control to avoid this and the binding should be passing through the two dependency properties.</p>
  <p>I was hoping to make the user control more generic later but cannot seem to even get it working in a basic fashion</p>
  <p>Quick call out to you Silverlight Binding masters :D</p>