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
The attachable property 'SelectedColumnIndex' was not found in type 'CustomDependencyProperty'. [Line: 17 Position: 74]
This is the code i used to declare my dependency property
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);
}
}
}
And this is my XAML code
<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">
<UserControl.Resources>
<local:SimpleConverter x:Key="myConverter"></local:SimpleConverter>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid x:Name="dataGrid"
AutoGenerateColumns="True"
ItemsSource="{Binding Responses}"
local:CustomDependencyProperty.SelectedColumnIndex="{Binding Index,Mode=TwoWay}">
</sdk:DataGrid>
<TextBlock x:Name="DisplayIndex" Text="{Binding Index}" />
</Grid>
</UserControl>
I am unable to figure out what excatly is the problem.Is there anything wrong in the way I declare a dependency property?
Please help.
Thanks, Alex