我正在尝试定义一个包含PasswordBox元素的设置页面。当我重建应用程序时,定义的文本资源不能正确显示。但是,如果我移除:
x:Uid="/resources/db_pwd" 定义(见下文),然后重新构建视图OK。如果我尝试用定义的资源链接初始化视图,那么我将得到下面的错误。它似乎是PasswordBox的文本属性.但它没有这个财产。很困惑!
资源
|Name | Value |
|-----------------------|---------------------------|
|db_pwd.Header |Password (default password)|
|db_pwd.PlaceholderText |Enter your password |
|db_pwd.Text |Password (default pwd) |密码箱
<PasswordBox x:Name="dbpwd" Width="300" x:Uid="/resources/db_pwd"
Header="Database Password"
PlaceholderText="Enter password"
PasswordChanged="PasswordBox_PasswordChanged"
HorizontalAlignment="Left" Margin="40,5,0,0" />错误初始化视图
Windows.UI.Xaml.Markup.XamlParseException
HResult=0x802B000A
Message=The text associated with this error code could not be found.
Unable to resolve property 'Text' while processing properties for Uid '/sql/db_pwd'. [Line: 38 Position: 68]
Source=Windows
StackTrace:
at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
at WeeWX.Views.SettingsPage.InitializeComponent() in D:\Dave\Documents\Visual Studio\WeeWX\obj\x86\Debug\Views\SettingsPage.g.i.cs:line 49
at WeeWX.Views.SettingsPage..ctor() in D:\Dave\Documents\Visual Studio\WeeWX\Views\SettingsPage.xaml.cs:line 49
at WeeWX.Views.MainPage.SetSettings(Object sender, TappedRoutedEventArgs e) in D:\Dave\Documents\Visual Studio\WeeWX\Views\MainPage.xaml.cs:line 350
This exception was originally thrown at this call stack:
[External Code]
WeeWX.Views.SettingsPage.SettingsPage() in SettingsPage.xaml.cs
WeeWX.Views.MainPage.SetSettings(object, Windows.UI.Xaml.Input.TappedRoutedEventArgs) in MainPage.xaml.cs 问题
发布于 2022-08-10 14:21:10
最后解决了这个问题,但是场景很重要:
最初的定义是一个PasswordBox
Text属性(假设TextBox的属性与PasswordBox.Content属性),因此我认为一定有一些缓存在进行。
H 112我又做了#3,重新启动VS,仍然没有成功地H 213/code>H 114我又做了#3,更改了db_pwd资源的名称,并引用<>d16,删除了db_pwd.Text,重建了解决方案.成功!
不确定修复这类问题需要采取哪些步骤,但底线是VS有一些非常愚蠢(过于乐观)的缓存正在进行!意见或建议?
PS:在将TextBox更改为HyperlinkButton之后,现在也有了类似的问题。修正通过一个类似的过程(步骤5)!
发布于 2022-08-06 01:23:47
回答你的问题:
1.为什么要查找文本属性,密码框没有此属性!?
2.即使在资源文件中添加文本条目(如图所示),它也会失败。为什么?
PasswordBox控件没有Text属性。它有一个Password属性。
3.造成此错误的根本原因是什么,以及修复?
要修复此错误,需要更改资源:
db_pwd.Text -> db_pwd.Password
https://stackoverflow.com/questions/73254692
复制相似问题