views:

184

answers:

2

Hi

I have a very simple WPF project comprising a Window and Usercontrol. I'm very much in a learning phase. It works fine when I run it. However, I am unable to see the form in design time. The problem, I believe is something to do with namespaces, but I don't understand where. It may well be a simple error

Main Window XML

<Window 
    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" 
    xmlns:views="clr-namespace:UserLogin"
    x:Class="UserLogin.MainView"
    x:Name="MainViewWindow"
    mc:Ignorable="d" 
    Title="Login" 
    Height="141" 
    Width="347"
    >

    <Grid>        
        <views:LoginView />
    </Grid>

</Window>

Main Window CodeBehind

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports UserLogin

Namespace UserLogin

    Partial Public Class MainView
        Inherits System.Windows.Window

        Public Sub New()
            InitializeComponent()
        End Sub

    End Class

End Namespace

Usercontrol XAML

<UserControl 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" 
             x:Class="UserLogin.LoginView"
             x:Name="LoginViewControl"
             mc:Ignorable="d" d:DesignHeight="96" d:DesignWidth="298">
    <Grid  Height="96" Width="298">
        <Button Command="{Binding OKCommand}" Height="21" Margin="0,0,90,16" Name="btnOK" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="76">OK</Button>
        <Button Command="{Binding CancelCommand}" Height="21" HorizontalAlignment="Right" Margin="0,0,9,16" Name="btnCancel" VerticalAlignment="Bottom" Width="75">Cancel</Button>
        <Label Height="23" HorizontalAlignment="Left" Margin="10,5,0,0" Name="Label1" VerticalAlignment="Top" Width="85">Name:</Label>
        <Label HorizontalAlignment="Left" Margin="10,32,0,0" Name="Label2" Width="85" Height="29" VerticalAlignment="Top">Password:</Label>
        <TextBox Margin="0,31,6,0" Name="txtPassword" Height="22" VerticalAlignment="Top" HorizontalAlignment="Right" Width="182" />
        <ComboBox Height="22" Margin="110,6,6,0" Name="cboNames" VerticalAlignment="Top" />
    </Grid>
</UserControl>

Usercontrol CodeBehind

Imports Microsoft.VisualBasic
Imports System
Imports UserLogin

Namespace UserLogin
    Partial Public Class LoginView
        Inherits System.Windows.Controls.UserControl

        Public Sub New()
            InitializeComponent()
        End Sub

    End Class
End Namespace

I think I'm missing something this namespace

xmlns:views="clr-namespace:UserLogin"

since intellisense doesn't give me the usercontrol declared within it in the XAML designer but rather reports the error "Unable to load the metadata for the assembly ... etc etc"

Thx for any suggestions

Simon

A: 

This may be a stupid question, but did you rebuild your project after creating the control? The Visual Studio WPF editor is incredibly finicky about finding assemblies, but "can't find metadata" almost always means that the assembly you're referencing doesn't exist.
Whenever you have a weird WPF designer issue, always rebuild and possibly restart VS.

JustABill
Thx. I've rebuilt/cleaned/deleted bin and obj etc numerous times. So tried to shutdown and re-open VS2010. Still no joy in getting the Usercontrol to appear in the Window in design time. Presumably since it appears to be okay in runtime, do you think it is safe to assume it is the designer?
Simon Woods
Alright, you've got me, I've never seen an error that stubborn. It sounds to me like the designer is somehow allergic to your control, but it's so simple I have no idea why that could happen. Try commenting out parts and see if it eventually reappears?
JustABill
I have done that as far as I think I can and narrowed it down to the line which references the namespace in the Main Window. I can take all the xaml (referencing controls) in the usercontrol and put it into the main window and it is fine. So I downloaded a wpf component from codeplex (BubbleBurst) and found I have similar problems. I'm beginning to wonder if I've not got something installed properly.
Simon Woods
I am experiencing this same error with VS2008. Simon, you accepted this answer but commented that it didn't work. Do you remember what you did to so solve this problem?
bufferz
A: 

are MainView and LoginView controls in the same assembly? If not, you need to include assembly info in the name space defn.

lneir
Thx. Yes they are.
Simon Woods