protected virtual void OnClearHighlightAdorner(HighlightAdorner adorner) { BindingOperations.ClearBinding(adorner, HighlightAdorner.FillProperty); BindingOperations.ClearBinding(adorner, HighlightAdorner.StrokeProperty); }
protected virtual void OnPrepareHighlightAdorner(HighlightAdorner adorner) { // TODO: figure out how to create a binding to "(TextSelection.Settings).HighlightFillProperty" in code TextSelectionSettings settings = EnsureSettings(); BindingBase isFocusedBinding = new Binding() { Path = new PropertyPath(FrameworkElement.IsFocusedProperty), Source = this.textBlock, Mode = BindingMode.OneWay }; adorner.SetBinding( HighlightAdorner.FillProperty, new MultiBinding() { Bindings = { isFocusedBinding, new Binding() { Path = new PropertyPath(TextSelectionSettings.HighlightFillProperty), Source = settings, Mode = BindingMode.OneWay }, new Binding() { Path = new PropertyPath(TextSelectionSettings.InactiveHighlightFillProperty), Source = settings, Mode = BindingMode.OneWay } }, Mode = BindingMode.OneWay, Converter = ToggleMultiConverter.Default } ); adorner.SetBinding( HighlightAdorner.StrokeProperty, new MultiBinding() { Bindings = { isFocusedBinding, new Binding() { Path = new PropertyPath(TextSelectionSettings.HighlightStrokeProperty), Source = settings, Mode = BindingMode.OneWay }, new Binding() { Path = new PropertyPath(TextSelectionSettings.InactiveHighlightStrokeProperty), Source = settings, Mode = BindingMode.OneWay } }, Mode = BindingMode.OneWay, Converter = ToggleMultiConverter.Default } ); }