You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI Windows平台如何禁用Entry控件的边框与下划线?

MAUI Windows平台下禁用Entry控件的边框与下划线方法

针对Windows平台,你之前尝试的代码未生效,核心原因是没覆盖TextBox(MAUI Entry对应的Windows原生控件)焦点状态下的默认视觉样式。以下是完整的有效实现:

Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(MdeEntry), (handler, view) =>
{
#if ANDROID
    handler.PlatformView.SetBackgroundColor(Android.Graphics.Color.Transparent);
#elif WINDOWS
    // 移除常规状态下的边框
    handler.PlatformView.BorderThickness = new Microsoft.UI.Xaml.Thickness(0);
    handler.PlatformView.BorderBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
    
    // 移除焦点状态下的高亮边框
    handler.PlatformView.FocusVisualPrimaryBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
    handler.PlatformView.FocusVisualPrimaryThickness = new Microsoft.UI.Xaml.Thickness(0);
    handler.PlatformView.FocusVisualSecondaryBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
    handler.PlatformView.FocusVisualSecondaryThickness = new Microsoft.UI.Xaml.Thickness(0);
#endif
});

关键说明

Windows原生TextBox控件除了常规状态的BorderThickness和BorderBrush,在获取焦点时还会显示默认的双层高亮边框,这部分由FocusVisualPrimaryBrush、FocusVisualPrimaryThickness等属性控制。只修改常规状态的属性无法完全消除所有边框视觉效果,必须同时覆盖这些焦点相关配置。

内容的提问来源于stack exchange,提问作者Denis Humeniuk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 21:05:08