我有下面的示例应用程序的代码:Xamarin形式 - 错误(仅在UWP)切换输入视图中的IsPassword当
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
}
}
}
PasswordPage.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项目并按照指南进行重现):
- 在主应用程序页面上单击ListView的任何项目。
- 在打开的页面上,单击“显示/隐藏”按钮两次。
- 返回上一页。
- 再次单击ListView的任何项目。
只有在切换“Entry”视图的“IsPassword”属性时,该错误才会出现在UWP/Windows上。如果单击“显示/隐藏”一次,则错误不会显示。
错误:
System.ArgumentException
The parameter is incorrect.
E_RUNTIME_SETVALUE
at Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, Object value) at Xamarin.Forms.Platform.UWP.EntryRenderer.UpdateIsPassword() at Xamarin.Forms.Platform.UWP.EntryRenderer.OnElementChanged(ElementChangedEventArgs'1 e) at Xamarin.Forms.Platform.UWP.VisualElementRenderer'2.SetElement(VisualElement element) at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element) at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e) at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load() at Xamarin.Forms.Platform.UWP.VisualElementRenderer'2.SetElement(VisualElement element) at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element) at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e) at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load() at Xamarin.Forms.Platform.UWP.VisualElementRenderer'2.SetElement(VisualElement element) at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element) at Xamarin.Forms.Platform.UWP.VisualElementExtensions.GetOrCreateRenderer(VisualElement self) at Xamarin.Forms.Platform.UWP.NavigationPageRenderer.SetPage(Page page, Boolean isAnimated, Boolean isPopping) at Xamarin.Forms.Platform.UWP.NavigationPageRenderer.OnPushRequested(Object sender, NavigationRequestedEventArgs e) at Xamarin.Forms.NavigationPage.d__90.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.Forms.NavigationPage.d__48.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at App1.App.d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_0(Object state) at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
你试图用这个做什么? private void Button_Clicked(object sender,EventArgs e) PasswordEntry.IsPassword =!PasswordEntry.IsPassword; } –
我试图切换PasswordEntry的外观作为密码(显示或隐藏带星号的文本)。像这样:https://jsfiddle.net/sqhs5fs1/2/ –
你的代码在我的电脑上工作。我没有看到任何错误 –