我有这个自定义控件,但无法从我的主 XAML 访问它的成员
<UserControl x:Class="FireflyMmwDiagnostics.Controls.RegisterTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Label Name="LabelRegisterTitle"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
public partial class RegisterTextBox : UserControl
{
public RegisterTextBox()
{
InitializeComponent();
}
public string RegisterTitle
{
get { return this.LabelRegisterTitle.Content.ToString(); }
set { this.LabelRegisterTitle.Content = value; }
}
Run Code Online (Sandbox Code Playgroud)
这就是我在 Main XAML 中遇到的错误,指出“成员 RegisterTitle 无法识别或无法访问”:
<Controls:RegisterTextBox RegisterTitle="This Is A Test"/>
Run Code Online (Sandbox Code Playgroud)
我看了几个 YouTube 视频,这正是他们所做的,并且出于某种原因对他们有用。请就此处可能出现的问题提供建议。谢谢!
尝试将您的财产更改为Dependency Properties
这应该会有所帮助,因为它有示例代码 -为什么我在 WPF 用户控件上看到 \xe2\x80\x9cmember is not recognize or is notaccessible\xe2\x80\x9d 错误?
\n\n更新
\n\n您的代码在不使用依赖项属性的情况下对我来说工作正常,因此可以尝试以下几件事:
\n\n</UserControl>Controls:RegisterTextBox使用小写\'c\',所以controls:RegisterTextBox