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!
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">
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:
</UserControl>
Controls:RegisterTextBox
to use a lower case 'c', so controls:RegisterTextBox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With