Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Custom User Control - "The member X is not recognized or accessible"

Tags:

c#

wpf

xaml

I have this custom control but cannot access its members from my 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; }
    }

And this is what I have in Main XAML where I get the error stating "The member RegisterTitle is not recognized or accessible":

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

I watched a couple of YouTube videos and this is exactly how they did it and it worked for them for some reason. Please advice on what could be the issue here. Thank you!

like image 479
SYB Avatar asked Sep 04 '15 13:09

SYB


2 Answers

You might need to rebuild in order for it to see RegisterTitle.

If that doesn't work, make sure you have defined in XAML where Controls is in your project, otherwise it definitely won't be able to see it!

For example:

<Window xmlns:Controls="clr-namespace:FireflyMmwDiagnostics.Controls.RegisterTextBox">
like image 193
Jamie P Avatar answered Oct 04 '22 10:10

Jamie P


Try changing your property to be declared as Dependency Properties

This should help as it has example code - Why am I seeing a “member is not recognized or is not accessible” error on my WPF User Control?

Update

Your code works OK for me without using Dependency Properties, so a couple of things to try:

  • In your control, make sure you end it with </UserControl>
  • Change Controls:RegisterTextBox to use a lower case 'c', so controls:RegisterTextBox
like image 29
Stuart Avatar answered Oct 04 '22 09:10

Stuart