2010-03-11 26 views
3

當我將不同的字體設置爲組框時,子控件也設置爲組框的字體。如何在組框中設置子控件的字體?

我必須爲每個子控件設置不同的字體屬性。

像我不得不孩子控制字體屬性設置爲

<GroupBox Font Size = "14"> <Label FontWeight"Normal" ,Font Size ="8"/> <TextBox FontWeight"Normal" ,Font Size ="8"/> </GroupBox> 

這是設置每個兒童組箱內每個字體屬性和最好的aprroach?

請建議!!

回答

3

如果你想在分組框內標籤是一個更小的尺寸,一切都在組框相匹配的分組框標題文本大小一樣,使用樣式:

<GroupBox FontSize="14" Header="Header Text"> 
    <GroupBox.Resources> 
    <Style TargetType="Label"> 
     <Setter Property="FontSize" Value="8" /> 
     <Setter Property="FontWeight" Value="Normal" /> 
    </Style> 
    </GroupBox.Resources> 

    <StackPanel> 
    <Label Text="Label Text" /> 
    <Label Text="Another Label" /> 
    <TextBlock Text="This will match the group header" /> 
    </StackPanel> 
</GroupBox> 

如果你想組框標題是從分組框中的所有文本不同,使用一個TextBlock頭球而不是字符串:

<GroupBox> 
    <GroupBox.Header> 
    <TextBlock Text="Header Text" FontSize="14" /> 
    </GroupBox.Header> 

    <StackPanel> 
    <Label Text="Label Text" /> 
    <Label Text="Another Label" /> 
    <TextBlock Text="This will be the default font" /> 
    </StackPanel> 

</GroupBox> 

這兩種技術可被組合成具有一種尺寸用於分組框中頭,另一個尺寸的標籤,以及第三(默認)大小爲GroupBox中的所有其他文本。

相關問題