删除自定义 Entry & 上的边框Xamarin Forms UWP 编辑器 [英] Remove borders on custom Entry & Editor for Xamarin Forms UWP
本文介绍了删除自定义 Entry & 上的边框Xamarin Forms UWP 编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在 Xamarin Forms 中处理 UWP 项目.
I am currently working with a UWP project in Xamarin Forms.
当我使用默认的 Entry &编辑器,它带有我希望删除的边框以及添加圆形背景.
When i use the default Entry & Editor, it comes with a border that i wish to remove as well as add a rounded background.
我已经设置了渲染器和一些代码,但边框仍然完好无损.
I have setup the renderer and some code, but the border is still intact.
[assembly: ExportRenderer(typeof(Xamarin.Forms.Entry), typeof(MyRenderer))]
namespace App1.UWP
{
class MyRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(Control != null)
{
Control.Background = null;
}
}
}
}
推荐答案
条目
只需在自定义渲染器中设置BorderThickness
.
[assembly: ExportRenderer(typeof(Xamarin.Forms.Entry), typeof(MyRenderer))]
namespace App1.UWP
{
class MyRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(Control != null)
{
Control.BorderThickness = new Windows.UI.Xaml.Thickness(0);
}
}
}
}
奇怪的是 Editor
的 EditorRenderer 不起作用(OnElementChanged 不触发),我们必须子类化 Editor
并为新类创建自定义渲染器.
Editor :
It's weird that EditorRenderer of Editor
does not work (OnElementChanged not trigger) , we have to subclass Editor
and create custom renderer for the new class .
public class MyEditor : Editor
{
}
//xaml
xmlns:local="clr-namespace:App1"
<local:MyEditor/>
自定义渲染器
[assembly: ExportRenderer(typeof(MyEditor), typeof(MyRenderer))]
namespace App1.UWP
{
class MyRenderer : EditorRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.BorderThickness = new Windows.UI.Xaml.Thickness(0);
}
}
}
}
这篇关于删除自定义 Entry & 上的边框Xamarin Forms UWP 编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文