c# - 我如何创建两个部分来重点关注和其他部分进行写作?

标签 c# xaml xamarin.forms

我用这个代码来聚焦条目,它是一个自定义条目

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
    base.OnElementPropertyChanged(sender, e);

    if (e.PropertyName == Entry.IsFocusedProperty.PropertyName )
    {
        //place1. this code is use to focus
    }

    // place2. here enter the text when the user written
}

我如何知道用户是否正在写入?但不要进入这两个地方。

最佳答案

选项1:您可以设置TextProperty来检查用户编辑情况。

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
    base.OnElementPropertyChanged(sender, e);

    if (e.PropertyName == Entry.IsFocusedProperty.PropertyName)
    {
        //place1. this code is use to focus
    }

    if (e.PropertyName == Entry.TextProperty.PropertyName)
    {
        //place2. this code is use to edit 

        var content = Element.Text;
    }
}

选项 2:

您可以设置 Entry 的 TextChanged

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

    if(Control!=null)
    {
        Element.TextChanged += Element_TextChanged;
    }

}

private void Element_TextChanged(object sender, TextChangedEventArgs e)
{
    // var content = Element.Text;
}

关于c# - 我如何创建两个部分来重点关注和其他部分进行写作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60678380/

相关文章:

ios - Xamarin.Forms - 强制重绘 ListView 布局

ios - 防止 Xamarin.Forms.iOS 中的编辑器自动滚动

java - 在 Unity 中使用 Google Api Java 类?

c# - 使用 Postman 将 GUID 列表发布到 MVC 5 Controller

c# - 为什么将 XAML 图像源设置为 URI 比使用 HttpClient 获取图像更快?

c# - 有没有办法将 Controls.ContextMenu 转换为 Forms.ContextMenu?

c# - XAML 的编译器参数?

c# - Xamarin 表单中的 SwipeListView

c# - ASP.NET Core 中 AppSettings.json 内的 POCO 对象数组

C# Outlook Mailitem ContextMenu 和 Ribbon 不能一起工作(只能单独使用)