In XAML, is it possible to define a global constant style without specifying the TargetType
I would like to define my logo color as a style then apply that color wherever. Something like this:
<Style x:Name="LogoBlue">
<Setter Property="Background" Value="#607C8C" />
</Style>
<TextBlock Background="{StaticResource LogoBlue}">Blah Blah</TextBlock>
Is it possi开发者_StackOverflowble to define a color constant as a static resource?
Define a brush as a resource in your App.xaml, then you can refer to it by its key.
As the colour is a fixed colour the PresentationOptions allows more efficient use of the brush as you will not change it's colour.
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="PresentationOptions"
StartupUri="MainWindow.xaml">
<Application.Resources>
<SolidColorBrush x:Key="LogoBlue" Color="#607C8C" PresentationOptions:Freeze="True"/>
</Application.Resources>
</Application>
精彩评论