【问题标题】:Xamarin forms - Error when toggling entry view's IsPassword (only on uwp)Xamarin 表单 - 切换条目视图的 IsPassword 时出错(仅在 uwp 上)
【发布时间】:2016-09-22 07:13:18
【问题描述】:

我有以下示例应用代码:

App.cs(入口点)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace App1
{
    public class ListItem
    {
        public string ItemText { get; set; }
        public string ItemDetail { get; set; }
        public string Password { get; set; }
    }


    public class App : Application
    {
        public App()
        {
            // The root page of your application
            var listView = new ListView
            {
                ItemTemplate = new DataTemplate(() =>
                {
                    var textCell = new TextCell();
                    textCell.SetBinding(TextCell.TextProperty, "ItemText");
                    textCell.SetBinding(TextCell.DetailProperty, "ItemDetail");
                    return textCell;
                }),
                VerticalOptions = LayoutOptions.FillAndExpand,
                ItemsSource = new List<ListItem>
                {
                    new ListItem
                    {
                        ItemText = "Item 1",
                        ItemDetail = "Detail 1",
                        Password = "123456"
                    },

                    new ListItem
                    {
                        ItemText = "Item 2",
                        ItemDetail = "Detail 2",
                        Password = "76432"
                    },
                    new ListItem
                    {
                        ItemText = "Item 3",
                        ItemDetail = "Detail 3",
                        Password = "66543"
                    },
                }
            };

            listView.ItemTapped += ListView_ItemTapped;

            var content = new ContentPage
            {
                Title = "App1",
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children =
                    {
                        new ScrollView
                        {
                            Content = new StackLayout
                            {
                                Padding = 10,
                                Children =
                                {
                                    listView
                                }
                            }
                        }
                    }
                }
            };

            MainPage = new NavigationPage(content);
        }

        private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            await this.MainPage.Navigation.PushAsync(new PasswordPage((e.Item as ListItem).Password));
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

密码页.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;

using Xamarin.Forms;

namespace App1
{
    public class PasswordPage : ContentPage
    {
        private string Password;
        private Entry PasswordEntry = new Entry();

        public PasswordPage(string password)
        {
            this.Password = password;
            PasswordEntry.IsPassword = true;
            PasswordEntry.Text = password;

            var button = new Button();
            button.Text = "Show/Hide";
            button.Clicked += Button_Clicked;

            Content = new StackLayout
            {
                Children = {
                    new Label { Text = "Password" },
                    PasswordEntry,
                    button
                }
            };
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            PasswordEntry.IsPassword = !PasswordEntry.IsPassword;
        }
    }
}

我在以下场景中出现以下错误,仅在UWP上(您可以download附件示例项目,运行UWP项目并按照指南进行重现):

  1. 在主应用程序页面上单击 ListView 的任何项目。
  2. 在打开的页面上,点击“显示/隐藏”按钮两次
  3. 返回上一页。
  4. 再次单击 ListView 的任何项目。

该错误仅在 UWP/Windows 上发生,并且仅当您切换“条目”视图的“IsPassword”属性时才会发生。如果单击“显示/隐藏”一次,则不会出现错误。

错误:

System.ArgumentException

参数不正确。

E_RUNTIME_SETVALUE

在 Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, 对象值)在 Xamarin.Forms.Platform.UWP.EntryRenderer.UpdateIsPassword() 在 Xamarin.Forms.Platform.UWP.EntryRenderer.OnElementChanged(ElementChangedEventArgs'1 吃 Xamarin.Forms.Platform.UWP.VisualElementRenderer'2.SetElement(VisualElement 元素)在 Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement 元素)在 Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(对象 发件人,ElementEventArgs e) 在 Xamarin.Forms.Platform.UWP.VisualElementPackager.Load() 在 Xamarin.Forms.Platform.UWP.VisualElementRenderer'2.SetElement(VisualElement 元素)在 Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement 元素)在 Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(对象 发件人,ElementEventArgs e) 在 Xamarin.Forms.Platform.UWP.VisualElementPackager.Load() 在 Xamarin.Forms.Platform.UWP.VisualElementRenderer'2.SetElement(VisualElement 元素)在 Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement 元素)在 Xamarin.Forms.Platform.UWP.VisualElementExtensions.GetOrCreateRenderer(VisualElement 自我)在 Xamarin.Forms.Platform.UWP.NavigationPageRenderer.SetPage(页面页面, Boolean isAnimated, Boolean isPopping) 在 Xamarin.Forms.Platform.UWP.NavigationPageRenderer.OnPushRequested(对象 发件人,NavigationRequestedEventArgs e) 在 Xamarin.Forms.NavigationPage.d__90.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Xamarin.Forms.NavigationPage.d__48.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在 App1.App.d__1.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.c.b__6_0(对象 州)在 System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()

Download Project Sample

【问题讨论】:

  • 你想用这个做什么? private void Button_Clicked(object sender, EventArgs e) { PasswordEntry.IsPassword = !PasswordEntry.IsPassword; }
  • 我正在尝试将 PasswordEntry 的外观切换为密码(显示或隐藏带有星号的文本)。像这样的东西:jsfiddle.net/sqhs5fs1/2
  • 您的代码在我的电脑上运行。我没有看到任何错误
  • 您执行了 UWP 项目并完全按照指南进行操作,没有出错?我的 PC 和 Windows 10 手机都出现错误
  • 我用你的代码在我的电脑 windows 10 pro 中执行代码,我没有任何问题。

标签: c# xamarin xamarin.forms


【解决方案1】:

看起来这实际上是表单中的一个错误。我已经为它提交了一个错误报告here

问题似乎与设置本机 TextBox 控件 InputScope 属性有关。我创建了一个 pull request 来进行修复,因此希望它很快会被合并并发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多