我有此自定义控件,但无法从我的Main 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>




public partial class RegisterTextBox : UserControl
{
    public RegisterTextBox()
    {
        InitializeComponent();
    }

    public string RegisterTitle
    {
        get { return this.LabelRegisterTitle.Content.ToString(); }
        set { this.LabelRegisterTitle.Content = value; }
    }


这就是我在Main XAML中遇到的错误,该错误指出“无法识别或访问成员RegisterTitle”:

<Controls:RegisterTextBox RegisterTitle="This Is A Test"/>


我观看了几个YouTube视频,这正是他们的制作方法,由于某些原因,它确实对他们有用。
请就这里可能存在的问题提出建议。
谢谢!

最佳答案

尝试将您的属性更改为声明为Dependency Properties

这有帮助,因为它有示例代码-Why am I seeing a “member is not recognized or is not accessible” error on my WPF User Control?

更新资料

您的代码无需使用依赖项属性就可以正常工作,因此可以尝试以下几件事:


在您的控件中,确保以</UserControl>结尾
更改Controls:RegisterTextBox以使用小写字母'c',因此controls:RegisterTextBox

07-28 02:55
查看更多