尝试在文本框上设置突出显示按钮,突出显示功能起作用。问题在于突出显示按钮显示文本突出显示,我希望它显示为按下但是当我选择突出显示的文本时,GetPropertyValue不会返回值。
工作高亮方法:
private void HighlightButton_Click(object sender, RoutedEventArgs e)
{
richEditControl.Focus();
var currentColour = richEditControl.Selection.GetPropertyValue(TextElement.BackgroundProperty);
if (currentColour == null || currentColour == DependencyProperty.UnsetValue)
{
richEditControl.Selection.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Yellow);
}
else
{
richEditControl.Selection.ApplyPropertyValue(TextElement.BackgroundProperty, null);
}
UpdateButtonStates();
}
来自UpdateButtonStates的片段,它不起作用。
var currentColour = richEditControl.Selection.GetPropertyValue(TextElement.BackgroundProperty);
if (currentColour == null || currentColour == DependencyProperty.UnsetValue)
{
HighlightButton.IsChecked = false;
}
else
{
HighlightButton.IsChecked = true;
}