Why am I being told a class does not exist in my n

2019-09-02 03:17发布

问题:

I am trying to follow the article here to add a custom control to my project so that I can call it ("promptForPhotosetName") like so:

Popup popTart = new Popup();
popTart.Child = new promptForPhotosetName();
popTart.IsOpen = true;

I added a Custom Control to my project based on Templated Control.

My custom control class (which IS in the Photrax namespace) contains this constructor:

public promptForPhotosetName()
{
    this.DefaultStyleKey = typeof(promptForPhotosetName);
}

I have this in \Themes\Generic.xaml, which is the other file (along with promptForPhotsetName.cs) that was created when I added the Custom Control:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Photrax">

    <Style TargetType="local:promptForPhotosetName">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:promptForPhotosetName">
                    <StackPanel Orientation="Vertical">
                        <ListBox >
                            <ListBoxItem>
                                <StackPanel  Orientation="Horizontal">
                                    <Image Source="Windows 8.jpg" Height="200" Width="300" Stretch="Fill"></Image>
                                    <Image Source="Windows_8.jpg" Height="200" Width="300"   Stretch="Fill"></Image>
                                    <Image Source="windows8(1).jpg" Height="200" Width="300"   Stretch="Fill">
                                    </Image>
                                </StackPanel>
                            </ListBoxItem>
                        </ListBox>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Yet I get this error: The name "promptForPhotosetName" does not exist in the namespace "using:Photrax"." on both this line of XAML:

<Style TargetType="local:promptForPhotosetName">

...and this one:

<ControlTemplate TargetType="local:promptForPhotosetName">

Why? The class promptForPhotosetName IS indeed in the Photrax namespace!

回答1:

Sounds like just the design tools error. Rebuilding the project should make the designer recognize the types it hasn't seen before.