View not found ViewModel in different assemblies

I am starting a new project and orienting my project structure to the structure recommended in this question .

Now I see strange behavior. When I set the datacontext in View-XAML, it is not found at runtime (receive XamlParseException). When I install it in the constructor in the codebehind file, everything works fine.

Is this the official (documented) behavior when using different assemblies, or am I doing something wrong?

The code:

Does not work:

MainView.xaml:

<UserControl x:Class="ViewsRoot.Views.MainView"             
         xmlns:baseControls="clr-namespace:BaseControls;assembly=BaseControls"            
         xmlns:viewModels="clr-namespace:ViewModelsRoot;assembly=ViewModelsRoot">
<UserControl.DataContext>
    <viewModels:ShellViewModel />
</UserControl.DataContext>

MainView.xaml.cs

public MainView() 
{
    InitializeComponent();
    // No DataContext set in codebehind-file    
}

AT:

MainView.xaml:

<UserControl x:Class="ViewsRoot.Views.MainView"             
         xmlns:baseControls="clr-namespace:BaseControls;assembly=BaseControls"            
         xmlns:viewModels="clr-namespace:ViewModelsRoot;assembly=ViewModelsRoot">
<!--<UserControl.DataContext>
    <viewModels:ShellViewModel />
</UserControl.DataContext> -->

MainView.xaml.cs:

public MainView()
{
    InitializeComponent();
    DataContext = new ViewModelsRoot.ShellViewModel();
}

Update:

Exceptional text:

{"File or assembly \" ViewModelsRoot, PublicKeyToken = null \ "or one of its dependencies was not found. The system cannot find the specified file." }

, , System.IO.FileNotFoundException.

2:

, . , , (). DataContexts intellisense. <viewModels:ShellViewModel /> intelli-sense. ...... ?

3: "Xaml" "" , DataContext .

+5
2

, , :

  • StartupProject → ViewsRoot
  • ViewsRoot → ViewModelsRoot
  • ViewModelsRoot

"StartupProject" "exe", "dll".

, "ViewModelsRoot" "StartupProject". , , "ViewModelsRoot.dll" "StartupProject".

DataContext , Visual Studio "dll" . DataContext XAML. , "ViewModelsRoot" XAML Reflection. Visual Studio "dll" .

"ViewModelsRoot.dll" , .

+3

, " " ( VS2010, IIRC), , 3.5 4.0.

-1

All Articles