3

これは簡単に思えますが、答えを見つけるのに苦労しています。

さまざまな領域の見出しと小見出しを使用する必要があるWPFウィンドウがあります。もちろん、各要素にスタイリングインラインを含めることもできますが、スタイリングを個別に維持したいと思います。さまざまな見出し/小見出し/「通常の」ラベルクラスを意味的に区別して、別のXAMLドキュメントで適切にスタイルを設定できるようにする正しい方法は何ですか?

ありがとう!

4

1 に答える 1

10

次のように、リソースディクショナリに必要な「ラベルクラス」ごとにスタイルを設定できます。

<Style x:Key="heading" TargetType="Label">
    <Setter Property="FontSize" Value="24" />
</Style>

<Style x:Key="subHeading" TargetType="Label">
    <Setter Property="FontSize" Value="16" />
</Style>

<Style x:Key="normal" TargetType="Label">
    <Setter Property="FontSize" Value="12" />
</Style>

そして、あなたの見解では、リソースを呼び出して次のように使用する必要があります。

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary 
                Source="Resources/MyResources.xaml">
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

<Grid>
    <Label Style="{StaticResource heading}" Content="This is a heading!" />
</Grid>
于 2012-08-20T17:31:45.490 に答える