0

This is my MainWindowViewModel.vb

Public Class MainWindowViewModel
Inherits ViewModelBase

Public Sub New()

End Sub

Private _test As String = "Success"
Public Property Test() As String
    Get
        Return _test
    End Get
    Set(ByVal value As String)
        _test = value
        RaisePropertyChanged()
    End Set
End Property

End Class

This is my MainWindow.xaml

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Koala"  
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <local:MainWindowViewModel x:Key="MainWindowViewModelDataSource" d:IsDataSource="True"/>
</Window.Resources>
<Grid DataContext="{Binding Source={StaticResource MainWindowViewModelDataSource}}">
    <TextBox HorizontalAlignment="Left" Height="23" Margin="156,103,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="{Binding Test}"/>
</Grid>
</Window>

And this is the error I get:

Error   1   The name "MainWindowViewModel" does not exist in the namespace "clr-namespace:Koala".   \\psf\Dropbox\Programming\Windows\Koala\Koala\MainWindow.xaml   7   3   Koala

I can add a reference to the namespace Koala in the Window tag without problems. When I type <local:, I get the option to use the MainWindowViewModel tag. Whenever I add the x:Key or not, from that moment the error occurs. (Re)building doesn't work, restarting VS2012 doesn't work. I searched dozens of similar problems but it I can't find a fix for mine.

I tried to add the reference through Blend and VS2012 but neither of them work. The odd thing is that I'm able to start the debug mode and see my form on the screen. Also, Success appears in the TextBox.

paparazzo
  • 42,665
  • 20
  • 93
  • 158
Krowi
  • 1,422
  • 3
  • 18
  • 37
  • I would create a new project and copy paste in the working code. – paparazzo Mar 02 '14 at 17:37
  • Did this twice now, always the same error. Starting to get the feeling this is just a bug because the program is getting compiled right and bindings work like intended. It's just annoying when you try to edit the view you can't see. – Krowi Mar 02 '14 at 17:53
  • possible duplicate of [The name "XYZ" does not exist in the namespace "clr-namespace:ABC"](http://stackoverflow.com/questions/16216662/the-name-xyz-does-not-exist-in-the-namespace-clr-namespaceabc) – safetyOtter Mar 02 '14 at 18:31

2 Answers2

0

Wrap your MainWindowViewModel class in

Namespace ViewModels
  Public Class MainWindowViewModel
  Inherits ViewModelBase
...
  End Class
End Namespace

And then add a new namespace to your window:

xmlns:vm="clr-namespace:Koala.ViewModels"

And use the vm prefix instead of local in your resources declaration.

safetyOtter
  • 1,298
  • 12
  • 23
  • Did what you suggested but the error is still there :/ – Krowi Mar 02 '14 at 17:02
  • Are you getting the MainWindowViewModel suggested after the vm: ? – safetyOtter Mar 02 '14 at 17:47
  • Yes I do. If I type ` – Krowi Mar 02 '14 at 17:51
  • This shouldn't matter, but is the MainWindowViewModel class in a folder in your project? – safetyOtter Mar 02 '14 at 17:56
  • Yes, MainWindowViewModel.vb is in the folder ViewModels in the same project. – Krowi Mar 02 '14 at 17:59
  • Very strange. There are a few other posts similar on SO like [this one](http://stackoverflow.com/questions/3304741/vs2010-getting-type-or-namespace-name-could-not-be-found-but-everything-seem), could it be any thing strange like that? ALSO! I just noticed your using a network share and there's a post in the right bar with the same error and it was the shares fault. Try the [answer on this one](http://stackoverflow.com/questions/16216662/the-name-xyz-does-not-exist-in-the-namespace-clr-namespaceabc?rq=1) – safetyOtter Mar 02 '14 at 18:06
  • You have to be kidding me... The project was on Dropbox, moving it to my personal folder fixed the problem. Thank you for linking me to that post, it fixed it! – Krowi Mar 02 '14 at 18:20
  • Excellent, glad to help. – safetyOtter Mar 02 '14 at 18:31
0

I had a similar problem with two UserControls present in two different dlls. I resolved the issue by adding assembly reference to the xaml like below

<Window x:Class="View.MainWindowView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:v1="clr-namespace:View1;assembly=MyAssemblyName1"
    xmlns:v2="clr-namespace:View2;assembly=MyAssemblyName2"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <v1:UserControl1/>
        <v2:UserControl2/>
    </Grid>
</Window>

My project is a .Net4.5 project with two dlls containing two UserControls and a Main WPF application

Please note the addition

assembly=MyAssemblyName1
resp78
  • 1,134
  • 10
  • 23