4

In a first attempt to create a DataTemplate I added the class from MainWindow to access eventhandlers. Now this may be incorrect for a number of reasons (and produces some interesting error messages) however I'd like to understand why a ResourceDictionary is unable to reference a partial class such as MainWindow ?

xaml as follows (note that this fails without any events implemented)

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Window.Resources>
    <ResourceDictionary>
            <ResourceDictionary Source="Dictionary1.xaml"/>
    </ResourceDictionary>
</Window.Resources>
</Window>

Resource dic.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
>

</ResourceDictionary>

Any thoughts much appreciated

Constanta
  • 399
  • 4
  • 15

1 Answers1

4

You cannot have a resource dictionary backed up by something like a MainWindow because MainWindow does not inherit from ResourceDictionary class.

See this article for better understanding of the use of code behind resource dictionaries ...

I hope this answers your question.

Community
  • 1
  • 1
WPF-it
  • 19,625
  • 8
  • 55
  • 71