c# - 如何在聚焦时使用代码更改富编辑框的背景?
问题描述
我试图让我的编辑框有黑色背景,所以我的构造函数如下所示:
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"
};
解决方案
因此,您可以检测何时在 UIElements 上获得和失去焦点...尝试键入 .Focus,您将看到处理程序...这将返回 RichTextBox 作为调用弧中的一个元素。然后在这里你改变你的颜色。
推荐阅读
- css - MaterialUI 如何为其类定义 CSS?
- sockets - 我可以在 TcpConnections 中检测到来自同一 IP 的不同客户端吗?
- microsoft-graph-api - /teams/{team-id}/channels/{channel-id}/messages 订阅不起作用
- git - 为什么每当我尝试查看内置颤振小部件的代码时,vs code 会显示这么多未跟踪的文件?
- maven - Maven如何从程序集中排除工件
- docker - 如何将 error_log 和 access_log 转发到 stderr 和 stdout 和文件
- javascript - 所有 react-run 命令都不起作用。| UnhandledPromiseRejectionWarning:DiscordAPIError:无法发送空消息
- php - 使用变量定位子数组并将其移动到主数组的顶部
- microsoft-teams - 更改 Microsoft 团队中已发布应用的 appName 和徽标
- windows - 分析 Windows 内存转储文件 - nt!TRIAGE_9F_POWER