2016-09-09 14 views
0

저는 WPF/C# 학습 프로젝트로 텍스트 편집기를 만들려고합니다.
세 개의 토글 버튼 (밑줄, 겹침 및 취소 선)이 있습니다.
- 이것들은 조합으로 나타날 수 있지만 어떻게 감지합니까? 내에서 selectionChanged 이벤트 핸들러RichTectBox 선택에서 여러 TextDecorations 감지

:

private void rt_SelectionChanged(object sender, RoutedEventArgs e) 
    { 
     bool IsTextUnderline = false; 
     bool IsTextStrikethrough = false; 
     bool IsOverline = false; 

     TextRange range = new TextRange(rt.Selection.Start, rt.Selection.End); 

     var decor = range.GetPropertyValue(Inline.TextDecorationsProperty); 

     if (decor != DependencyProperty.UnsetValue) 
      { 
      TextDecorationCollection coll = (TextDecorationCollection)decor; 

      IsTextStrikethrough = (coll.Contains(TextDecorations.Strikethrough)); 

그러나 .Contains()는 매개 변수로 TextDecorationCollection 기대 ...
- 무엇이든 그 - 완전히 혼란

답변

0

내가 (가까이 그냥 [0]을 놓친 의미), 작동하는 것은 다음과 같습니다.

private void rt_SelectionChanged(object sender, RoutedEventArgs e) 
{ 
    Object temp = rt.Selection.GetPropertyValue(Inline.TextDecorationsProperty); 
    if (temp.ToString() != "{DependencyProperty.UnsetValue}") // multivalue, can't handle..? 
    { 
     TextDecorationCollection decs = (TextDecorationCollection)temp; 
     btnUnderl.IsChecked = decs.Contains(TextDecorations.Underline[0]); 
     btnStrike.IsChecked = decs.Contains(TextDecorations.Strikethrough[0]); 
     btnBaseli.IsChecked = decs.Contains(TextDecorations.Baseline[0]); 
     btnOverli.IsChecked = decs.Contains(TextDecorations.OverLine[0]); 
    } 
}