Pergunta

I created a custom control in C# which has its template defined in Themes/Generic.xaml. The control (along with Themes/Generic.xaml) is defined in a project which outputs to a DLL. I'm not sure if this is important, but the control is in a subfolder.

When I reference the control from the main executable, OnApplyTemplate() in the control's C# is never called, and the control shows up with no style information applied.

This only happens in the release build; the debug build works fine.

If I redefine the template in the resources of the control hosting the control (e.g. Window.Resources) the control works fine. It seems that Visual Studio is not linking Themes/Generic.xaml to the control.

Foi útil?

Solução

It turns out that I had an empty "en-US" folder inside the release output folder, left over from a localization experiment. Apparently the WPF/.NET engine tried to load the control template from the "en-US" folder, and when it failed, did not revert back to the template defined in the assembly.

The solution was simple - delete the folder.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top