在xamarin 中隐藏软键盘(使得Entry控件有焦点且隐藏键盘)

如何声明自定义Entry,详见以下内容
https://learn.microsoft.com/zh-cn/xamarin/xamarin-forms/app-fundamentals/custom-renderer/entry

C#代码

public class MyEntry : Entry
{

}

Android中代码

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Text;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using App5;
using App5.Droid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace App5.Droid
{

public class MyEntryRenderer : EntryRenderer
{
    public MyEntryRenderer(Context context) : base(context)
    {
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {

        base.OnElementChanged(e);

        if (Control != null)
        {

            EditText editText = Control;

            editText.InputType = Android.Text.InputTypes.Null;
        }

    }


}

}

Xaml 中代码

要先引用名称空间
xmlns:local=“clr-namespace:App5”
<local:MyEntry x:Name=“myentry” Placeholder=“click me !but I can’t load keyboard 😃”/>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Xamarin连接到SQL Server可以通过以下步骤实现: 1. 首先,确保你已经安装了Microsoft.Data.SqlClient NuGet 包。在Visual Studio,可以通过右键点击项目,选择“管理NuGet程序包”来搜索并安装此包。 2. 在你的Xamarin项目,创建一个用于连接到SQL Server的类。你可以命名为 `SqlHelper.cs` 或者其他你喜欢的名称。 3. 在这个类,使用以下代码示例建立与SQL Server的连接: ```csharp using System.Data.SqlClient; public class SqlHelper { private static string connectionString = "Data Source=YourServerName;Initial Catalog=YourDatabaseName;User ID=YourUsername;Password=YourPassword"; public static SqlConnection GetConnection() { return new SqlConnection(connectionString); } } ``` 请确保替换 `YourServerName`、`YourDatabaseName`、`YourUsername` 和 `YourPassword` 为你的SQL Server的实际连接信息。 4. 现在,你可以在其他类使用 `SqlHelper` 类来执行SQL查询。例如,可以使用以下代码来查询一个表: ```csharp using (SqlConnection connection = SqlHelper.GetConnection()) { string query = "SELECT * FROM YourTable"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { // 处理查询结果 } } ``` 这是一个简单的例子,你可以根据需要进行修改和扩展。请注意,在实际应用,最好使用异步方法来执行数据库操作,以避免阻塞UI线程。 这就是在Xamarin连接到SQL Server的基本步骤。希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值