title: "The attachable property not found in type " error while using a dependency property in Silverlight
body: <p>I am trying to do some sample applications to use Dependency Property in a DataGrid,but when i tried to run application I am getting an run time exception </p>
  
  <blockquote>
    <p>The attachable property 'SelectedColumnIndex' was not found in type
    'CustomDependencyProperty'. [Line: 17 Position: 74]</p>
  </blockquote>
  
  <p>This is the code i used to declare my dependency property</p>
  
  <pre><code>public class CustomDependencyProperty : DataGrid
  {
  
      public static DependencyProperty SelectedColumnIndexProperty = DependencyProperty.Register("SelectedColumnIndex",
                                                                                                   typeof(object),
                                                                                                   typeof(DataGrid),
                                                                                                   new PropertyMetadata(0));
  
      public int SelectedColumnIndex
      {
          get
          {
              return (int)GetValue(SelectedColumnIndexProperty);
          }
  
          set
          {
              SetValue(SelectedColumnIndexProperty, value);
          }
      }
  }
  </code></pre>
  
  <p>And this is my XAML code</p>
  
  <pre><code>&lt;UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="BindingDictionary.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
               xmlns:local="clr-namespace:BindingDictionary"
               xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
      mc:Ignorable="d"
      d:DesignHeight="300" d:DesignWidth="400"&gt;
      &lt;UserControl.Resources&gt;
          &lt;local:SimpleConverter x:Key="myConverter"&gt;&lt;/local:SimpleConverter&gt;
      &lt;/UserControl.Resources&gt;
          &lt;Grid x:Name="LayoutRoot" Background="White"&gt;
          &lt;sdk:DataGrid x:Name="dataGrid"
                        AutoGenerateColumns="True"
                        ItemsSource="{Binding Responses}" 
                        local:CustomDependencyProperty.SelectedColumnIndex="{Binding Index,Mode=TwoWay}"&gt;
          &lt;/sdk:DataGrid&gt;
          &lt;TextBlock x:Name="DisplayIndex" Text="{Binding Index}" /&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I am unable to figure out what excatly is the problem.Is there anything wrong in the way I declare a dependency property?</p>
  
  <p>Please help.</p>
  
  <p>Thanks,
  Alex</p>