首页 > 解决方案 > 如何在聚焦时使用代码更改富编辑框的背景?

问题描述

我试图让我的编辑框有黑色背景,所以我的构造函数如下所示:

GUI = new RichEditBox()
        {
            Margin = new Thickness(0, 510, 0, 0),
            Width = 550,
            Height = 250,
            Background = new SolidColorBrush(Colors.White),
            IsSpellCheckEnabled = false,
            IsColorFontEnabled = true,
            IsEnabled = false,
            IsTextScaleFactorEnabled = false,
            Opacity = 0,
            SelectionFlyout = null,
            FontFamily = new FontFamily("Consolas"),
            FocusVisualPrimaryBrush = new SolidColorBrush(Colors.Black),
            FocusVisualSecondaryBrush = new SolidColorBrush(Colors.Black),
            Foreground = new SolidColorBrush(Colors.Black),
            UseSystemFocusVisuals = false,
            Header = "Bash"
        };

问题是编辑框在选择时看起来像这样: 选中时框

但是当它没有被选中并且鼠标在盒子里面时,它看起来正是我想要的: 盒子我想要的

标签: c#xamluwpricheditbox

解决方案


因此,您可以检测何时在 UIElements 上获得和失去焦点...尝试键入 .Focus,您将看到处理程序...这将返回 RichTextBox 作为调用弧中的一个元素。然后在这里你改变你的颜色。


推荐阅读