J'essaie de créer un éditeur de texte en tant que projet d'apprentissage WPF/C#.
J'ai 3 boutons à bascule (souligné, souligné et barré).
- elles peuvent apparaître en combinaison, mais comment les détecter?Détection de plusieurs TextDecorations dans la sélection RichTectBox
Mon selectionChanged eventhandler:
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));
Mais .Contains() attend un TextDecorationCollection comme paramètre ...
- tout à fait déroutant