TextElement.FontStyle Свойство

Определение

Получает или задает стиль шрифта для содержимого элемента.

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

Значение свойства

Требуемый стиль шрифта. Значение по умолчанию определяется значением MessageFontStyle.

Примеры

В следующем примере показано, как задать атрибут FontStyle, используя элемент Paragraph в качестве образца.

<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>

На следующем рисунке показано, как выполняется отрисовка предыдущего примера.

Снимок экрана: текст с набором свойств текста

В следующем примере показано, как программным образом присвоить значение свойству FontStyle.

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

Комментарии

Это свойство зависимостей также использует присоединенное свойство. В XAML используется <object TextElement.FontStyle="value".../>, где object — это элемент объекта (обычно элемент потока), содержащийся в TextElement, а value — одно из имен свойств в строковом FontStyles формате в классе . В коде использование присоединенного свойства поддерживается методами GetFontStyle и SetFontStyle . Присоединенное свойство используется не так часто, так как большинство элементов, которые могут содержаться в TextElement , поддерживают аналогичное несоединяемое FontStyle свойство, которое узел содержимого использует для отрисовки.

Сведения о свойстве зависимостей

Поле идентификатора FontStyleProperty
Для свойств метаданных задано значение true AffectsMeasure, AffectsRender, Inherits

Применяется к