Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

UserControl XAML Not Recognizing Code-Behind Class Name

$
0
0

I have developed various UserControls in a WPF solution called CustomControls.  Once developed, I can copy the 2 xaml files for a control into a new solution ad use it there (or compile into a library, which I'm not presently doing).

Now I'm having a strange problem, and can't figure it out.  Here is partial XAML and code-behind for one of the custom controls which is working just fine:

<UserControl x:Class="RonM.CustomCheckBox" x:Name="ccb"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" 
             MinHeight="40" MinWidth="20" Height="100" Width="50"><UserControl.Resources>
Namespace RonM

    Public Class CustomCheckBox
        Inherits UserControl
        Implements INotifyPropertyChanged

        Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
        Private Sub NotifyPropertyChanged(ByVal info As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
        End Sub

        Public Sub New()

            ' This call is required by the designer.
            InitializeComponent()

Now, I'm trying to add a new UserControl called CustomScrollbar.  so I right-click on the solution, choose Add, select WPF and UserControl, give it a name, then click OK.  Now I have CustomScrollbar.xaml and CustomScrollbar.xaml.vb in my project.. Here are the file contents so far:

<UserControl x:Class="RonM:CustomScrollbar"
             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></Grid></UserControl>
Namespace RonM

    Public Class CustomScrollbar

    End Class
End Namespace

So the problem is, when I try to build the solution I get this error:
x:Class="RonM:CustomScrollbar" is not valid. 'RonM:CustomScrollbar' is not a valid class name. Line 1 Position 14.

If I remove the "RonM:" from the first line of the XAML file, it builds ok, but then I end up with 2 different user controls in my project, one with and one without namespace in the user control name in the toolbox.  If I try to insert the one with the namespace into my MainWindow, it is empty.  If I insert the one WITHOUT the namespace into my MainWindow, it seems to be ok.

So what am I doing wrong?  The other 3 UserControls work just fine with a namespace declaration.  It seems like I should be able to add a new one using the same syntax, right?

It's probably something very simple, but I can't see it.

Thanks...


Ron Mittelman


Viewing all articles
Browse latest Browse all 18858

Trending Articles