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();
}
AT:
MainView.xaml:
<UserControl x:Class="ViewsRoot.Views.MainView"
xmlns:baseControls="clr-namespace:BaseControls;assembly=BaseControls"
xmlns:viewModels="clr-namespace:ViewModelsRoot;assembly=ViewModelsRoot">
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 .