0
votes

I am creating a universal app in Visual Studio 2015. My universal app has a reference to a universal library called UIComponents.

In UIComponents I created a user control:

namespace MyProj.UIComponents {
  public sealed partial class MyControl : UserControl
  {
    public MyControl()
    {
      this.InitializeComponent();
    }
  }
}

With the following xaml:

<UserControl
    x:Class="MyProj.UIComponents.MyControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyProj.UIComponents"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid>
        <Rectangle Fill="White" HorizontalAlignment="Left" Height="280" Stroke="Black" VerticalAlignment="Top" Width="380" Margin="10,10,0,0"/>
        <TextBox x:Name="textBox" Margin="20,20,20,20" TextWrapping="Wrap" Text="TextBox"/>

    </Grid>
</UserControl>

Inside my app project, which references UIComponents, I do this:

<Page
    x:Class="MyProj.App.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyProj.App"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="using:MyProj.UIComponents"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <ui:MyControl></ui:MyControl>
    </Grid>
</Page>

But when I try to get the designer display the page I get:

enter image description here

The error list shows this:

The name "MyControl" does not exist in the namespace "using:MyProj.UIComponents".

Funny thing is that the whole solution builds just fine, but the designer is not collaborating.

Attempt using clr-namespace

There are similar questions about this in WPF, so not strictly universal apps, and they are marked as solved on answers where the solution was to use:

xmlns:ui="clr-namespace:MyProj.UIComponents" 

Bu that does not work:

Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'MyProj.UIComponents' that could not be found.

1
Move over a bit, you are blocking our view on the Error List.Hans Passant
Yeah sorry forgot to post the errorAndry
It is doubtful that the class name is "MyProj.UIComponents.MyControl.MyControl". So it surely should be "using:"MyProj.UIComponents" instead..Hans Passant
I pasted the wrong string sorry, I fixed itAndry
Explain the downvote, otherwise people cannot understand what they did wrong...Andry

1 Answers

0
votes

The error list shows this:

The name "MyControl" does not exist in the namespace "using:MyProj.UIComponents".

In my experience, this could probably be caused by

  1. The UIComponents Library didn't got built.

    After building the Library project, VS will add the following codes into YourProject.proj file, which will be detected by VS designer:

    <ItemGroup>//The following lines will be added.
       <Page Include="MyControl.xaml">
       <Generator>MSBuild:Compile</Generator>
          <SubType>Designer</SubType>
       </Page>
    </ItemGroup>
    

    So, please try building your library project and rereference it in your main project.After reloading, designer should load the contents correctly.

    Notes: The architecture(x64,x86) when building your library should be identical to current architecture. (e.g. when you build your library with x86. Designer can't load correctly, when your current architure is x64).

  2. The namespace is wrong, which seems not the main cause here.