简体   繁体   中英

UserControl in Windows Phone 8.x project can't be found: “The type or namespace name 'UserControls' does not exist in the namespace”

I have a windows phone project where I've added a usercontrol:

namespace MyApp.WindowsPhone.UserControls
{
    public partial class SlidingUpOverlay : UserControl
    {
        public SlidingUpOverlay()
        {
            InitializeComponent();
       }
    }
}

Then I'm referencing it in a Page like this:

<phone:PhoneApplicationPage
    x:Class="MyApp.WindowsPhone.UI.TopUpPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:userControls="clr-namespace:MyApp.WindowsPhone.UserControls">



<userControls:SlidingUpOverlay x:Name="SlidingUpOverlay" Visibility="Collapsed" />

But building it gives me following error:

The type or namespace name 'UserControls' does not exist in the namespace 'MyApp.WindowsPhone.MyApp.WindowsPhone' (are you missing an assembly reference?)    MyApp-WP C:\Users\MyApp\developers\apps\MyApp-WP\MyApp-WP\obj\Debug\UI\TopUpPage.g.i.cs

I've cleaned bin and obj-folders, restarted computer, restarted VS2015, tried everything suggested but nothing works. I've also read through many pages here on stackoverflow but haven't found anything the suggests anything else than I've already tried. What am I missing?

xmlns:userControls="clr-namespace:MyApp.WindowsPhone.UserControls"

您可以尝试将此行更改为:

xmlns:userControls="using:MyApp.WindowsPhone.UserControls"

Change the namespace of user control:

namespace MyApp
{
    public partial class SlidingUpOverlay : UserControl
    {
        public SlidingUpOverlay()
        {
            InitializeComponent();
       }
    }
}

Then add the following reference in your Xaml Page:

xmlns:userControls="clr-namespace:MyApp">

PS Also change the Xaml schema of your User control

x:Class="MyApp.SlidingUpOverlay"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM