use*_*915 2 customization custom-renderer xamarin.forms xamarin.uwp xamarin.forms.entry
是否有可能将Entry的半径自定义为略微圆角?
您可以Custom Renderer在xamarin.forms中使用
在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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Android中
在Resource-> drawable文件夹中创建一个xml文件 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>
Run Code Online (Sandbox Code Playgroud)
在 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) );
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在UWP
创建一个名为Styles的文件夹并添加一个新项目作为类型资源字典,并将其命名为Dictionary1.xaml中的Dictionary1.xaml将此代码放入一个圆角文本框中.
在 Custom Renderer
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"];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何更改此样式以及如何创建此代码?这很简单,在msdn.com中搜索uwp中的"objectName"默认样式,然后你会找到你需要的对象的默认样式.以您想要的方式更改它并直接将其添加到应用程序资源或链接它(就像我在这里所做的那样)然后在CustomRenderer中加载您的样式
有关UWP的详细信息,请参阅此处
在表格中
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace App11
{
public class MyEntry : Entry
{
public MyEntry()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
在xxx.cs文件中
Content = new StackLayout
{
Children = {
new MyEntry {Text = "In Shared Code",}
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
745 次 |
| 最近记录: |