Ich habe eine benutzerdefinierte WPF-Steuerbibliothek mit MVVM-Bibliotheken.Erstellen Sie einen Verweis auf Locator in einem ResourceDictionary
im Wörterbuch Ich habe:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
<local:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
Und in Window.xaml ich versuchen, dass Locator zu verwenden:
<Window x:Class="WPFCustomeControlLibrary.Window"
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"
mc:Ignorable="d"
Title="Window" Height="300" Width="300"
DataContext="{Binding MainViewModel, Mode=OneWay, Source={StaticResource Locator}}">
<Window.Resources>
<ResourceDictionary Source="Dictionary.xaml" />
</Window.Resources>
<Grid>
</Grid>
Aber es sagt noch ‚Die Ressource Locator konnte nicht aufgelöst werden.
Locator ist mein ViewModelLocator, in dem mein MainViewModel definiert ist.
Warum Sie es in einem Ressourcenverzeichnis an erster Stelle setzen? –
@ThomasV da es keine andere Option in einer benutzerdefinierten WPF-Steuerbibliothek gibt. – user7998549