WPF Binding Runtime Error "Expected Property"

I am trying to bind an observable collection to a WPF DataGrid. One of my properties is bool. I don't like DataGrid CheckboxColumn, so I applied my own TemplateColumn, which I bind to a public property in the DataContext. The project designs, compiles and works fine. However, in the designer, Visual Studio 2013 Professional underlines the anchor path in red. When I hover over him, he says "Intended Property". Oddly enough, it doesn't appear in the error list, but a red "error marker" appears in the scroll bar. Also, if I use the "standard" CheckboxColumn, VS does not display the underline.

Here's my DataContext class:

sealed class Connection : IDisposable
{
    public bool Log { get; set; }

    public int HashCode { get; private set; }
}

      

And this is the DataGrid XAML:

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=Connections}" SelectionMode="Single">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=HashCode, StringFormat={}{0:X}}" Header="ID" IsReadOnly="True" Width="50*"/>
        <DataGridTemplateColumn Header="Log">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=Log, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

      

Here is a screenshot of the error:

Error

Oddly enough, VS does a great job with this XAML, which I don't want to use because of the column behavior:

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=Connections}" SelectionMode="Single">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=HashCode, StringFormat={}{0:X}}" Header="ID" IsReadOnly="True" Width="50*"/>
        <DataGridCheckBoxColumn Binding="{Binding Path=Log, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="Log" />
    </DataGrid.Columns>
</DataGrid>

      

As I said, it compiles and works fine. Is this a bug in Visual Studio?

+3


source to share


1 answer


Try specifying the datatype for the DataTemplate like this:



<DataTemplate DataType="wpfApplication1:Connection">
    <CheckBox ... />
</DataTemplate>

      

+4


source







All Articles