■ RichTextBox 클래스 : 선택 문자열의 속성값 설정하기 예제

----------------------------------------------------------------------------------------------------

SetSelectionStringPropertyValue<FontFamily>(richTextBox, FlowDocument.FontFamilyProperty, fontFamily);

 

SetSelectionStringPropertyValue<double>(richTextBox, FlowDocument.FontSizeProperty, fontSize);

 

SetSelectionStringPropertyValue<FontWeight>(richTextBox, FlowDocument.FontWeightProperty, fontWeight);

 

SetSelectionStringPropertyValue<FontStyle>(richTextBox, FlowDocument.FontStyleProperty, fontStyle);

 

SetSelectionStringPropertyValue<Brush>(richTextBox, FlowDocument.BackgroundProperty, backgroundBrush);

 

SetSelectionStringPropertyValue<Brush>(richTextBox, FlowDocument.ForegroundProperty, foregroundBrush);

 

SetSelectionStringPropertyValue<TextAlignment>(richTextBox, FlowDocument.TextAlignmentProperty, textAlignment);

----------------------------------------------------------------------------------------------------

 

■ RichTextBox 클래스 : 선택 문자열의 속성값 설정하기

----------------------------------------------------------------------------------------------------

using System.Windows;

using System.Windows.Controls;

 

#region 선택 문자열 속성 값 설정하기 - SetSelectionStringPropertyValue<TValue>(richTextBox, dependencyProperty, propertyValue)

 

/// <summary>

/// 선택 문자열 속성 값 설정하기

/// </summary>

/// <typeparam name="TPropertyValue">속성 값 타입</typeparam>

/// <param name="richTextBox">RichTextBox 객체</param>

/// <param name="dependencyProperty">DependencyProperty 객체</param>

/// <param name="propertyValue">속성 값</param>

public void SetSelectionStringPropertyValue<TPropertyValue>(RichTextBox richTextBox,

    DependencyProperty dependencyProperty, TPropertyValue propertyValue)

{

    richTextBox.Selection.ApplyPropertyValue(dependencyProperty, propertyValue);

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요