3

I'm having an issue with a Universal Windows App and viewing a UserControl in Design view and Blend.

I have a BaseUserControl and some ValueConverters in the in the Shared Library. I reference the value converters in the App.xaml and the BaseUserControl is the Base for a specific UserControl I want to use Blend to help design.

I'm currently getting design-time errors in the Visual Studio XAML designer and in Blend:

The name "BaseUserControl" does not exist in the namespace "using:MyProject.Controls".

The designer view and Blend shows a box with the message:

Invalid Markup - Check the Error List for more information

I can build the project and run it and everything shows up and works fine.

How can I get the Shared Library code to be recognized in the Designer/XAML View and Blend?

UserControl is defined like so:

<controls:BaseUserControl
        x:Class="MyProject.Controls.Menu.LeftNavigation"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyProject.Controls.Menu"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:controls="using:MyProject.Controls"
        mc:Ignorable="d"
        Background="#232323"
        d:DesignHeight="800"
        d:DesignWidth="110"
        >
...
</controls:BaseUserControl>

The code behind is simply:

namespace MyProject.Controls.Menu
{
    public sealed partial class LeftNavigation : BaseUserControl
    {
        public LeftNavigation()
        {
            this.InitializeComponent();
        }
    }
}
codekaizen
  • 26,990
  • 7
  • 84
  • 140
BeaverProj
  • 2,205
  • 1
  • 17
  • 31

1 Answers1

2

I notice that you use controls:BaseUserControl which expands to MyProject.Controls.BaseUserControl. However, in your Code Behind you have set the namespace to MyProject.Controls.Menu. This will prevent the designer from finding your control.

Change the controls tag to:

xmlns:controls="using:MyProject.Controls.Menu"

Alternatively, change the namespace in the code behind to MyProject.Controls and then you can leave the xmlns:controls tag alone.

Also, I have seen the designer fail to notice new controls in the shared library in Universal apps (now called Windows Apps) developed in Visual Studio 2013 even when the namespace is correct. This can happen if the shared library was stale when you added your xaml tag to the page. If this happens, remove any of your attempts to include controls:BaseUserControl in your xaml temporarily.

Then, clean the solution and rebuild it. This will allow the Shared Library to rebuild properly, exposing the new tag to the designer. Finally, add your tag back in after the build is successful and build again.

I hope that helps someone. I just struggled with this very issue today.