2016-09-09 5 views
0

私はWPF/C#学習プロジェクトとしてテキストエディタを作ろうとしています。
私は3つのトグルボタン(下線、上書き、取り消し線)を持っています。
- これらは組み合わせて表示されますが、どのように検出できますか?マイselectionChangedのEventHandlerRichTectBox選択で複数の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]); 
    } 
}