WPF Global style definitions with .Net4

Posted by stiank81 on Stack Overflow See other posts from Stack Overflow or by stiank81
Published on 2010-04-29T09:13:13Z Indexed on 2010/04/29 9:17 UTC
Read the original article Hit count: 781

Filed under:
|
|
|

I have a WPF application using .Net3.5. I'm now trying to change the target framework to .Net4, but I run into some problems with my style definitions.

I have most style definitions in a separate project. Some are global styles that address specific components like e.g. <Button> controls that doesn't have explicit style defined. And some are styles defined with a key such that I can reference them explicitly.

Now, the controls that have an explicit style referenced are displayed correctly after changing to .Net4. This goes also for explicit style references in the separate project. However, all global styles are disabled. Controls like e.g. <Button>, that I use the global style for everywhere, now appears without any style.

Why?! Does .Net4 require a new way for defining global styles? Or referencing ResourceDictionaries? Anyone seen similar problems?

I have tried replacing my style definitions with something very simple:

<Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Red"></Setter>
</Style>

It still doesn't work. I moved this directly to the ResourceDictionary of the app.xaml, and then it works. I moved it to the ResourceDictionary referenced by the one in app.xaml, and it still works. This ResourceDictionary merges several dictionaries, one of them is the dictionary where the style was originally defined - and it doesn't work when being defined there. Note that there are other style definitions in the same XAML that does work - when being explicitly defined.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about .net-4.0