Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Style in Application.Resources on All Windows

 
 
Old 05-01-2006   #1 (permalink)
Stefc


 
 

Style in Application.Resources on All Windows

I try to give all my Windows the same background. To do this I think I
should set a style in the Application.Resources with TargetType = "{x:Type
Window}". This won't work, the background isn't set.

If I use the concrete types of my windows it works as expected. But I must
set for each Window class a style. Better would be that one global setting
on this.

<Style TargetType="{x:Type local:MainWindow}">

<Setter Property="Background" Value="{StaticResource WindowBackground}"/>

</Style>

<Style TargetType="{x:Type dlgs:AboutDialog}">

<Setter Property="Background" Value="{StaticResource WindowBackground}"/>

</Style>

Why the following Code not work ?

<Style TargetType="{x:Type Window}">

<Setter Property="Background" Value="{StaticResource WindowBackground}"/>

</Style>

"MainWindow" and either "AboutDialog" are descendants of Window ???

- Mfg Stefc-



My System SpecsSystem Spec
Old 05-01-2006   #2 (permalink)
viliescu


 
 

RE: Style in Application.Resources on All Windows

It's because the unnamed styles apply only to the type specified in the
TargetType, it will not affect derived types. I don't know what is the
rationale behind this design decision but this is the way it works.
--
Valentin Iliescu [MVP - Client Application Development]


"Stefc" wrote:

> I try to give all my Windows the same background. To do this I think I
> should set a style in the Application.Resources with TargetType = "{x:Type
> Window}". This won't work, the background isn't set.
>
> If I use the concrete types of my windows it works as expected. But I must
> set for each Window class a style. Better would be that one global setting
> on this.
>
> <Style TargetType="{x:Type local:MainWindow}">
>
> <Setter Property="Background" Value="{StaticResource WindowBackground}"/>
>
> </Style>
>
> <Style TargetType="{x:Type dlgs:AboutDialog}">
>
> <Setter Property="Background" Value="{StaticResource WindowBackground}"/>
>
> </Style>
>
> Why the following Code not work ?
>
> <Style TargetType="{x:Type Window}">
>
> <Setter Property="Background" Value="{StaticResource WindowBackground}"/>
>
> </Style>
>
> "MainWindow" and either "AboutDialog" are descendants of Window ???
>
> - Mfg Stefc-
>
>
>

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Font Size - XP style vs Vista style Vista General
Font Size - XP style vs Vista style Vista General
Font Size - XP style vs Vista style Vista General
Windows XP style folders Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46