ページ内をナビゲートするナビゲーション要素を持つViewModelを格納するアプリケーションリソースをアプリケーションで定義しています。これは、すべてのデータバインディングがそこで動作しているので、ビジュアルスタジオのxamlエディタで正常に動作しています。しかし、私がデバッガでアプリケーションを実行しようとすると、例外がメッセージとともに返されます。Cannot find source with the name ViewModelLocator.
誰かが間違っていることを知っていますか?WPF実行時にローカルリソースを見つけることができません
私はこのような私のApp.xamlで定義されたローカルリソース持っている:私はこのように使用してみてください
<Application.Resources>
<viewmodel:ViewModelLocator x:Key="ViewModelLocator"/>
</Application.Resources>
:
<Page x:Class="QardPrint.PageEmployeesList"
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:QardPrint"
xmlns:viewmodel="clr-namespace:QardPrint.ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageEmployeesList"
DataContext="{Binding EmployeesListViewModel, Source={StaticResource ViewModelLocator}}">
マイViewModelLocatorクラスは、この
public class ViewModelLocator
{
public EmployeesListViewModel EmployeesListViewModel => new EmployeesListViewModel(App.Navigation);
}
のように見えます
'ViewModelLocator'と' App.xaml'は同じアセンブリ内にありますか? –
はい両方が同じアセンブリにあります。彼らは別の名前空間にありますが、私は同じ名前空間に入れようとしましたが、例外はまだポップアップしました。 –