Επεξεργασία

Κοινή χρήση μέσω


TextElement.FontStyle Property

Definition

Gets or sets the font style for the content of the element.

public:
 property System::Windows::FontStyle FontStyle { System::Windows::FontStyle get(); void set(System::Windows::FontStyle value); };
public System.Windows.FontStyle FontStyle { get; set; }
member this.FontStyle : System.Windows.FontStyle with get, set
Public Property FontStyle As FontStyle

Property Value

The desired font style. The default is determined by the MessageFontStyle value.

Examples

The following example shows how to set the FontStyle attribute, using Paragraph as the example element.

<Paragraph
  FontFamily="Century Gothic, Courier New"  
  FontSize="16pt"
  FontStretch="UltraExpanded"
  FontStyle="Italic"
  FontWeight="DemiBold"
>
  <Run>
    This text will use the Century Gothic font (if available), with fallback to Courier New.  It 
    will render with a font size of 16 points in ultra-expanded demi-bold italic.
  </Run>
</Paragraph>

The following figure shows how the preceding example renders.

Screenshot: Text with text properties set

The following example shows how to set the FontStyle property programmatically.

Run run = new Run(
    "This text will use the Century Gothic font (if available), with fallback to Courier New."
    + "It will render with a font size of 16 pixels in ultra-expanded demi-bold italic.");
Paragraph par = new Paragraph(run);

par.FontFamily = new FontFamily("Century Gothic, Courier New");
par.FontSize = 16;
par.FontStretch = FontStretches.UltraExpanded;
par.FontStyle = FontStyles.Italic;
par.FontWeight = FontWeights.DemiBold;
Dim run As New Run("This text will use the Century Gothic font (if available), with fallback to Courier New." & "It will render with a font size of 16 pixels in ultra-expanded demi-bold italic.")
Dim par As New Paragraph(run)

With par
    .FontFamily = New FontFamily("Century Gothic, Courier New")
    .FontSize = 16
    .FontStretch = FontStretches.UltraExpanded
    .FontStyle = FontStyles.Italic
    .FontWeight = FontWeights.DemiBold
End With

Remarks

This dependency property also has an attached property usage. In XAML, the usage is <object TextElement.FontStyle="value".../>, where object is an object element (typically a flow element) contained within a TextElement, and value is one of the string-format property names in the FontStyles class. In code, the attached property usage is supported by the GetFontStyle and SetFontStyle methods. The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached FontStyle property, which the content host uses for rendering.

Dependency Property Information

Identifier field FontStyleProperty
Metadata properties set to true AffectsMeasure, AffectsRender, Inherits

Applies to