2011-07-13 4 views
1

ロゴの色をスタイルとして定義し、その色をどこにでも適用したいと考えています。このようなもの:XAMLでは、TargetTypeを指定せずにグローバルコンスタントスタイルを定義することが可能です

<Style x:Name="LogoBlue"> 
    <Setter Property="Background" Value="#607C8C" /> 
</Style> 

<TextBlock Background="{StaticResource LogoBlue}">Blah Blah</TextBlock> 

色定数を静的リソースとして定義できますか?

答えて

0

App.xamlのリソースとしてブラシを定義し、そのキーで参照できます。

PresentationOptionsでは、色が固定されているため、ブラシの色を変更しなくても効率的に使用できます。

<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> 
関連する問題