Ho il seguente codice per un Expander:WPF: La formattazione di un'etichetta
<Expander Name="CompanyLinks" Header="{StaticResource companyLinksHeader}"
FontSize="18" FontFamily="Calibri" FontWeight="Bold">
<StackPanel>
<Label Content="{StaticResource companyLinksItemSummary}"
FontSize="14" FontFamily="Calibri" FontWeight="Bold"/>
<Label Content="{StaticResource companyLinksItemInfo}"
FontSize="14" FontFamily="Calibri" FontWeight="Bold"/>
<Label Content="{StaticResource companyLinksItemIssues}"
FontSize="14" FontFamily="Calibri" FontWeight="Bold"/>
<Label Content="{StaticResource companyLinksItemMessages}"
FontSize="14" FontFamily="Calibri" FontWeight="Bold"/>
</StackPanel>
</Expander>
I StaticResources sono definiti come segue (nel mio dizionario risorse):
<sys:String x:Key="companyLinksHeader">company</sys:String>
<sys:String x:Key="companyLinksItemSummary">summary</sys:String>
<sys:String x:Key="companyLinksItemInfo">info</sys:String>
<sys:String x:Key="companyLinksItemIssues">issues</sys:String>
<sys:String x:Key="companyLinksItemMessages">messages</sys:String>
C'è un modo per definire una voce di dizionario (o qualcos'altro) che gestirà lo stile Font per l'intestazione e le etichette in modo che non debba definire lo stesso carattere più e più volte (e cambiarlo solo in un punto, se voglio cambiare il carattere) ?
EDIT
ho trovato una soluzione (grazie a coloro che hanno postato) e sto usando il seguente stile per le voci Label StackPanel:
<!-- Expander Items text style -->
<Style x:Key="expanderItemsTextStyle">
<Setter Property="Label.FontFamily" Value="Trebuchet MS"></Setter>
<Setter Property="Label.FontWeight" Value="Normal"></Setter>
<Setter Property="Label.FontSize" Value="14"></Setter>
<Setter Property="Label.Foreground" Value="Aqua"></Setter>
</Style>
e l'attuazione in questo modo (applicandolo a StackPanel in modo che colpisce tutte le etichette):
<Expander Name="CompanyLinks" Header="{StaticResource companyLinksHeader}"
Style="{StaticResource expanderHeaderTextStyle}">
<StackPanel Style="{StaticResource expanderItemsTextStyle}">
<Label Content="{StaticResource companyLinksItemSummary}"/>
<Label Content="{StaticResource companyLinksItemInfo}" />
<Label Content="{StaticResource companyLinksItemIssues}" />
<Label Content="{StaticResource companyLinksItemMessages}" />
</StackPanel>
</Expander>
una cosa che non funziona anche se è il Label.Foreground. Il colore di primo piano rimane nero ma posso modificare il carattere, la dimensione o il peso tramite lo stile. Se sposto lo stile nella definizione Etichetta anche se il colore funziona. È un bug o esiste una proprietà diversa che imposterà il colore del carattere (in primo piano) delle etichette StackPanel.
È possibile creare uno stile comune e applicarlo alle etichette. – ryadavilli
Grazie. Cercavo la formattazione delle etichette e non lo stile. Ho trovato la risposta una volta ho cercato lo stile. – BrianKE
@BrianKE aggiornato per includere StackPanel –