xamarin.forms - 入口圆角 - Xamarin 形成 UWP
解决方案
您可以 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;
}
}
}
}
在安卓中
在文件夹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>
在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 中
创建一个名为 Styles 的文件夹,并将一个新项目添加为 Resource Dictionary 类型,并将其命名为 Dictionary1.xaml 中的 Dictionary1.xaml 将此代码用于圆形 Textbox 。
在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"];
}
}
}
}
如何更改此样式以及如何创建此代码?很简单,在 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()
{
}
}
}
在 xxx.cs 文件中
Content = new StackLayout
{
Children = {
new MyEntry {Text = "In Shared Code",}
},
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
推荐阅读
- string - 比较2个字符串,在python中使用list判断A是否包含B中的所有字符
- c# - 我的数据是否由于多线程而损坏?
- java - Spring Boot Application SSL 属性配置:setKeyStorePassword 之前的 getKeyStorePassword
- javascript - 如何从ajax响应中解码url?
- javascript - 带有固定 y 轴标题的 HTML 表格溢出-y 滚动
- python - 将 1D numpy 数组添加/堆叠到 2D numpy 数组
- intellij-idea - IntelliJ Kotlin/JS Mocha 单元测试无法通过插件进行
- php - 从 ftp 服务器读取 txt 在 fclose 上的 codeigniter 上出现错误
- python - 单元测试文件的文件命名约定
- matlab - 如何计算两个相交面下的体积?