I have a WPF project (NET6) with a MainWindow and a some views referenced in the MainWindow. The views are in the MainProject with the MainWindow. I have moved my ViewModels in a different project in a class library NET6.
And now the views referenced in the MainWindow are not working, it says: The view does not exist in the current namespace.
There are absolutely no errors, the namespaces are correct as if I move the ModelViews back into the project it solves the View namespace problem
Any idea what the problem can be and how to solve it?
This is the Main Window:
<Window x:Class="CRMT.MainWindow"
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:local="clr-namespace:CRMT"
xmlns:view="clr-namespace:CRMT.View"
xmlns:viewModel = "clr-namespace:CRMT.ViewModels.ViewModel;assembly=CRMT.ViewModels"
mc:Ignorable="d"
Title="RCMT" Height="262" Width="500"
Icon="voice.ico">
<Window.Resources>
<DataTemplate DataType="{x:Type viewModel:StartViewModel}">
<view:StartView />
</DataTemplate>
<DataTemplate DataType="{x:Type viewModel:StopViewModel}">
<view:StopView />
</DataTemplate>
<DataTemplate DataType="{x:Type viewModel:EndViewModel}">
<view:EndView />
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Grid.Row="1" Content="{Binding SelectedViewModel}" />
</Grid>
</Window>
This is one of the view:
<UserControl x:Class="CRMT.View.StopView"
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"
xmlns:local="clr-namespace:CRMT.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="Green" >
<Button Margin="10" Width="75" Command="{Binding AddCommand}">
<StackPanel Orientation="Horizontal">
<Image Source="/Resources/Images/add.png" Height="18" Margin="0 0 5 0"/>
<TextBlock Text="Add"/>
</StackPanel>
</Button>
</Grid>
</UserControl>
This is the one of the view xaml.cs
using System.Windows.Controls;
namespace CRMT.View
{
public partial class StopView : UserControl
{
public StopView()
{
InitializeComponent();
}
}
}
This is the View Model for the StopView:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using CRMT.ViewModels.Command;
namespace CRMT.ViewModels.ViewModel
{
public class StopViewModel : ViewModelBase
{
public DelegateCommand StopCommand { get; }
public StopViewModel() {
StopCommand = new DelegateCommand(Stop);
}
private void Stop(object? parameter)
{
}
}
}