进入的圆角-Xamarin形成UWP [英] Rounded corner for Entry - Xamarin forms UWP
问题描述
是否可以将Entry的半径自定义为稍微圆角?
Is there anything possible to customize the radius of Entry to having a slightly rounded corner?
推荐答案
您可以在xamarin.forms中使用 Custom Renderer
You can use Custom Renderer
in xamarin.forms
在iOS
in iOS
//...
using App11;
using App11.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyiOSEntry))]
namespace App11.iOS
{
public class MyiOSEntry:EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Layer.MasksToBounds = true;
Control.Layer.CornerRadius = 10; //set the rounded corner
Control.Layer.BorderColor = UIColor.Red.CGColor;
Control.Layer.BorderWidth = 3;
}
}
}
}
在Android
in Android
在文件夹资源->可绘制 edit_text_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid
android:color="#ffffff" />
<corners
android:radius="10dp" />
<stroke
android:width="2dp"
android:color="#3bbdfa" />
</shape>
</item>
在$code中>自定义渲染器
in Custom Renderer
using Android.Support.V4.Content.Res;
using App11;
using App11.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyAndriodEntry))]
namespace App11.Droid
{
public class MyAndriodEntry:EntryRenderer
{
public MyAndriodEntry(Context context):base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
Control.SetBackground(ResourcesCompat.GetDrawable(Resources, Resource.Drawable.edit_text_style, null) );
}
}
}
}
在UWP中的
in UWP
创建一个名为Styles的文件夹,并添加一个新项作为Resource Dictionary类型,然后将其命名为Dictionary1.xaml
在Dictionary1.xaml中,将此代码用于舍入的文本框。
create a folder named Styles and add a new item as type Resource Dictionary and name it Dictionary1.xaml in Dictionary1.xaml put this code for a rounded Textbox .
在自定义渲染器$ c $中c>
using App11;
using App11.UWP;
using Windows.UI.Xaml.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyUWPEntry))]
namespace App11.UWP
{
public class MyUWPEntry:EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
Control.Style = (Windows.UI.Xaml.Style)App11.UWP.App.Current.Resources["StyleRoundedTextBox"];
}
}
}
}
如何更改此样式以及如何创建此代码?
很简单,在msdn.com中,在uwp中搜索 objectName默认样式,然后即可找到所需对象的默认样式。以您想要的方式更改它,并将其直接添加到应用程序资源中或进行链接(如我在此处所做的那样),然后在CustomRenderer中加载样式
how do I changed this style and how do I create this code ? It's simple , in msdn.com search for "objectName" default style in uwp then you will find default style for the object you need . change it in the way you want and add it to application resources directly or link it (like what I did here) then load your style in CustomRenderer
以获取有关UWP的更多详细信息您可以在此处
for more detail about UWP yo can refer here
形式
in Forms
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace App11
{
public class MyEntry : Entry
{
public MyEntry()
{
}
}
}
在xxx.cs文件中
Content = new StackLayout
{
Children = {
new MyEntry {Text = "In Shared Code",}
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
这篇关于进入的圆角-Xamarin形成UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!