在 Xamarin.Forms 实现密码输入EntryCell
在 Xamarin.Forms 中,我们通常使用 TableView 来构建输入表单。Xamarin 为我们提供了 EntryCell 用于输入文本,但是其并不支持密码输入,即密码掩码。这里要对 EntryCell 进行扩展,使其支持密码输入。
首先,我们需要在共享项目(多平台项目)中增加控件定义,我们称之为:ExtendedEntryCell
/// <summary>
/// An extended entry cell control that allows set IsPassword
/// </summary>
public class ExtendedEntryCell : EntryCell
{ /// <summary>
/// The IsPassword property
/// </summary>
public static readonly BindableProperty IsPasswordProperty = BindableProperty.Create<ExtendedEntryCell, bool>(p => p.IsPassword, false); /// <summary>
/// Gets or sets IsPassword
/// </summary>
public bool IsPassword
{
get { return (bool)GetValue(IsPasswordProperty); }
set { SetValue(IsPasswordProperty, value); }
}
}
我们需要在Android和iOS中加入各自的Render。
Android 平台的 Render:
using Android.Content;
using Android.Text.Method;
using Android.Views;
using Android.Widget;
using WsLink.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using View = Android.Views.View; [assembly: ExportRenderer(typeof(ExtendedEntryCell), typeof(ExtendedEntryCellRenderer))] namespace App.Controls
{
public class ExtendedEntryCellRenderer : EntryCellRenderer
{
protected override View GetCellCore(Cell item, View convertView, ViewGroup parent, Context context)
{
var cell = base.GetCellCore(item, convertView, parent, context);
var textField = (cell as EntryCellView)?.EditText as TextView; if (textField != null && textField.TransformationMethod != PasswordTransformationMethod.Instance)
{
textField.TransformationMethod = PasswordTransformationMethod.Instance;
}
return cell;
}
}
}
iOS 平台的 Render
using UIKit;
using WsLink.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS; [assembly: ExportRenderer(typeof(ExtendedEntryCell), typeof(ExtendedEntryCellRenderer))] namespace WsLink.App.Controls
{
public class ExtendedEntryCellRenderer : EntryCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var entryCell = (ExtendedEntryCell) item;
var cell = base.GetCell(item, reusableCell, tv);
if (cell != null)
{
var textField = (UITextField) cell.ContentView.Subviews[];
textField.SecureTextEntry = entryCell.IsPassword;
}
return cell;
}
}
}
使用方法
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:WsLink.App.Controls"
x:Class="App.Account.LoginPage" Title="登录">
<TableView Intent="Form">
<TableSection>
<EntryCell Label="账户" Placeholder="账户" Text="{Binding Username}"></EntryCell>
<controls:ExtendedEntryCell IsPassword="True" Label="密码" Placeholder="密码" Text="{Binding Password}"></controls:ExtendedEntryCell>
</TableSection>
</TableView>
</ContentPage>
在 Xamarin.Forms 实现密码输入EntryCell的更多相关文章
- Xamarin.Forms教程开发的Xcode的下载安装
Xamarin.Forms教程开发的Xcode的下载安装 Xamarin.Forms教程开发的Xcode的下载安装,Xcode是开发iOS应用程序的图形化开发工具.本节将讲解Xamarin.Forms ...
- 菜鸟的Xamarin.Forms前行之路——windows下VS运行ios模拟器调试
在Xamarin.Forms项目中,运行安卓模拟器是很方便的,但是想要运行IOS模拟器,相对而言是困难一点. 在参考一些资料后,发现很多是与Xamarin.studio有关的方法,尝试了许久没有成功. ...
- Xamarin.Forms教程下载安装Xamarin.iOS
Xamarin.Forms教程下载安装Xamarin.iOS 下载安装Xamarin.iOS Xamarin.iOS可以为Mac上iOS应用程序在Windows计算机上编写和测试网络提供构建和部署服务 ...
- Xamarin.Forms应用程序基础知识
生命周期 在 Android 上,若主活动的 [Activity()] 属性缺少 ConfigurationChanges = ConfigChanges.ScreenSize | ConfigCha ...
- Xamarin.Forms登录对话框及表单验证
微信公众号:Dotnet9,网站:Dotnet9,问题或建议,请网站留言: 如果您觉得Dotnet9对您有帮助,欢迎赞赏. Xamarin.Forms登录系统 内容目录 实现效果 业务场景 编码实现 ...
- Xamarin.Forms 简介
An Introduction to Xamarin.Forms 来源:http://developer.xamarin.com/guides/cross-platform/xamarin-forms ...
- 使用Xamarin.Forms平台开发移动应用指南
下载书:链接: http://pan.baidu.com/s/1c29H9KG 密码: 7esm 注:捣鼓虚拟机把Hyper-V关闭,后来Xamarin搞挂了,所以暂停翻译. 第1章 Xamarin. ...
- Xamarin.Forms入门-使用 Xamarin.Forms 来创建跨平台的用户界面
Xamarin.Forms 是一个跨平台的.基于原生控件的UI工具包,开发人员可以轻松的创建适用于 Android,iOS 以及 Windows Phone的用户界面.Xamarin.Forms 通过 ...
- Xamarin.Forms入门学习路线
Xamarin 介绍 Xamarin是一套跨平台解决方案,目的是使用C#语言创造原生的iOS,Android,Mac和Windows应用. Xamarin的三个优势: Xamarin App拥有原生A ...
随机推荐
- Django——test文件编写接口测试
用自己建立的小网页来做接口测试,在Django的tests.py写下如下 test_login_page为用get方式登录login路径,根据回复验证是否查看到页面 test_login_action ...
- linux部署MantisBT(一)部署apache
一.部署apache 1.下载apache安装包及依赖包 http://httpd.apache.org/download.cgi#apache24(apache2)http://apr.apache ...
- 用树莓派Raspberry Pi和Micro:bit做一个自拍器
在这个项目中,我们将使用Python来构建一个由Micro:bit触发树莓派Raspberry Pi和相机模块的自拍器.这是开始使用硬件和简单文本编程的好方法. 我们将学习: 如何设置Raspberr ...
- 论文笔记:DeepFace: Closing the Gap to Human-Level Performance in Face Verification
2014 CVPR Facebook AI研究院 简单介绍 人脸识别中,通常经过四个步骤,检测,对齐(校正),表示,分类 论文主要阐述了在对齐和表示这两个步骤上提出了新的方法,模型的表现超越了前人的工 ...
- I understand that you would like to know about the Amazon Giveaway
Dear Seller, Greetings from Amazon Seller Support. From your mail, I understand that you would like ...
- KETTLE设置变量
一.kettle变量类型 kettle变量分为: 1.环境变量 通过 set variables组件设置变量,范围可以是:JVM变量.作业变量.父作业变量.根作业变量.使用时通过${var}或 %%v ...
- LeetCode 48. Rotate Image (C++)
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- psp项目计划
日期/任务 听课 编写程序 阅读书籍 查阅资料 日总计 周一 2h 0.5h 2.5 周二 1h 1 周三 1h 周四 2h 0.5h 2.5 周五 3 ...
- 大学网站UI设计分析(以学校领导/历届领导为例)
第一次的冲刺阶段让我过了一把PM的瘾,第一阶段的冲刺完成以后第一感觉就是PM不好当,在大学里做个课程设计当个PM相对而言还是比较容易的,但是我明白,当我们走向工作岗位以后,面临的情况会比学校的情况的复 ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...