© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
13 replies
Anton

WPF custom property not recognized by the compiler

I have defined a custom property like below, it's in the namespace
CarApp
CarApp
. It is supposed to represent the binding source that I would "pass" to a control template, defined as a static resource, by it grabbing it from the parent.
public static class TemplateBinding
{
    public static readonly DependencyProperty Property = DependencyProperty.RegisterAttached(
        typeof(TemplateBinding).Name, ownerType: typeof(DataGridColumn), propertyType: typeof(string));

    public static string Get(DataGridColumn target)
    {
        return (string) target.GetValue(Property);
    }

    public static void Set(DataGridColumn target, string value)
    {
        target.SetValue(Property, value);
    }
}
public static class TemplateBinding
{
    public static readonly DependencyProperty Property = DependencyProperty.RegisterAttached(
        typeof(TemplateBinding).Name, ownerType: typeof(DataGridColumn), propertyType: typeof(string));

    public static string Get(DataGridColumn target)
    {
        return (string) target.GetValue(Property);
    }

    public static void Set(DataGridColumn target, string value)
    {
        target.SetValue(Property, value);
    }
}

Then, at the top of my xaml component file, I define a local namescope like this
xmlns:local="clr-namespace:CarApp"
xmlns:local="clr-namespace:CarApp"
. Then, further on, I define my control template, and then my
DataGridTemplateColumn
DataGridTemplateColumn
like this:
<Grid.Resources>
    <DataTemplate x:Key="datePicker">
        <DatePicker SelectedDate="{Binding RelativeSource={RelativeSource TemplatedParent},
                Path=(local:TemplateBinding.Property)}"/>
    </DataTemplate>
</Grid.Resources>

<!-- ... -->

<DataGrid.Columns>
    <DataGridTemplateColumn
        Header="ManufacturedOn"
        CellTemplate="{StaticResource datePicker}"
        local:TemplateBinding.Property="ManufacturedDate" />
</DataGrid.Columns>
<Grid.Resources>
    <DataTemplate x:Key="datePicker">
        <DatePicker SelectedDate="{Binding RelativeSource={RelativeSource TemplatedParent},
                Path=(local:TemplateBinding.Property)}"/>
    </DataTemplate>
</Grid.Resources>

<!-- ... -->

<DataGrid.Columns>
    <DataGridTemplateColumn
        Header="ManufacturedOn"
        CellTemplate="{StaticResource datePicker}"
        local:TemplateBinding.Property="ManufacturedDate" />
</DataGrid.Columns>

When I try to compile the app, there's an error:
error MC3072: The property 'TemplateBinding.Property' does not exist in XML namespace 'clr-namespace:CarApp'. Line 59 Position 21.
error MC3072: The property 'TemplateBinding.Property' does not exist in XML namespace 'clr-namespace:CarApp'. Line 59 Position 21.

Which points to the line where I apply the property.
Clearing the temp files (obj) does not help. What's weird tho, is that removing the
App.xaml
App.xaml
(the entry point) and then compiling doesn't compain about that, it now says that there's no entry point, and the IDE doesn't show me an error in the
xaml
xaml
file, so I guess it compiled, but there might be error order at play too.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

WPF ListView.HeaderTemplate property not found
C#CC# / help
3y ago
Custom ToggleButon WPF
C#CC# / help
2y ago
❔ wpf custom window
C#CC# / help
3y ago