0
votes

I created a DateTimeConverter to convert my datetimes to MM/dd/yyyy format. I tried using it in my xaml file as:

<Window.Resources>
    <converters:DateTimeConverter Key="DateTimeConverter"/>
</Window.Resources>

and it caused an error saying: Property Key was not found in type DateTimeConverter.

Then after a bit of googling, I changed it to:

<Window.Resources>
    <converters:DateTimeConverter x:Key="DateTimeConverter"/>
</Window.Resources>

and it worked (note the "x:" before Key).

My "x" is defined by default as: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

It is working now, but I don't know why. Can someone please throw some light?

1

1 Answers

0
votes

Adding an x:Key value to a XAML object element is the most common way to identify a resource in a resource dictionary.

It's the syntax chosen for WPF xaml. Key property or attribute doesn't exist.

Refer to MSDN specs for more clarification.