Mike Dinescu
Mike Dinescu

Reputation: 55750

VisulStudio 2012 designer doesn't recognize properties of DataGrid correctly

In a WPF user control declaration I have the following style define:

<UserControl.Resources>
  <Style x:Key="Datagrid" TargetType="{x:Type DataGrid}">
     <Setter Property="Background" Value="Transparent"/>

     <Setter Property="BorderBrush" Value="Transparent"/>
     <Setter Property="HeadersVisibility " Value="Column"/>
     <Setter Property="VerticalGridLinesBrush " Value="{StaticResource DatagridVerticalLinesBrush}"/>
     <Setter Property="HorizontalGridLinesBrush " Value="Transparent"/>
     <Setter Property="RowHeaderWidth " Value="0"/>
     <Setter Property="CanUserAddRows " Value="False"/>
     <Setter Property="CanUserDeleteRows " Value="False"/>
  </Style>
</UserControl.Resources>

The problem is that the Visual Studio 2012 designer thinks the properties don't exist on the type DataGrid. It says that: the member "XXXXXXXXXXXX" is not recognized or is not accessible.

Despite the errors, the style is applied correctly at run time and the properties exist on the DataGrid (they are DependencyProperies) and are public.

Any idea what could be causing it to think they don't exist or why are they inaccessible to the designer?

By the way, the Background property is ok. It's only the other 7 that have errors.

Upvotes: 0

Views: 463

Answers (2)

jschroedl
jschroedl

Reputation: 4986

It may be a cut/paste error but you have an extra space before the closing double-quotes on all the property names except for Background and BorderBrush. The parser probably trims the property name before reflection so it's able to find it at runtime.

Upvotes: 1

JoeEngineer
JoeEngineer

Reputation: 106

I have loaded this up in VS2012, created a UserControl, added the above style. I observed that the Background and BorderBrush properties are seen as valid, but the others are not.

Then...I noticed the spaces in the quoted names. Once removed all is well...

<UserControl.Resources>
    <Style x:Key="Datagrid" TargetType="{x:Type DataGrid}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="HeadersVisibility" Value="Column"/>

        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="VerticalGridLinesBrush" Value="{StaticResource DatagridVerticalLinesBrush}"/>
        <Setter Property="HorizontalGridLinesBrush" Value="Transparent"/>
        <Setter Property="RowHeaderWidth" Value="0"/>
        <Setter Property="CanUserAddRows" Value="False"/>
        <Setter Property="CanUserDeleteRows" Value="False"/>
    </Style>
</UserControl.Resources>

Upvotes: 1

Related Questions