C#C
C#7mo ago
Fuxsy foxシ

✅ How to use ResourceDictionary in the App.xaml?

I want to build an application with Dependency Injection and I've finished everything. All that's left is to make the DataTemplate for all the windows.
Now I tried to do this using a new DataTemplate.xaml file but it doesn't work for me because the file doesn't see the other functions. for example

 xaml
    <DataTemplate DataType="{x:Type vm:TweaksVM}">
        <view:Tweaks />
    </DataTemplate>

I added the correct namespaces at least I think so
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:view="clr-namespace:WinRep_Code.Views"
                    xmlns:vm="clr-namespace:WinRep_Code.ViewModels">


and i got these errors
The name "Tweaks" does not exist in the namespace "clr-namespace:WinRep_Code.Views".
The name "TweaksVM" does not exist in the namespace "clr-namespace:WinRep_Code.ViewModels".

I guess I don't know how to use this in the App.xaml file but I don't know anymore
added the file tree
C:.
│   App.xaml
│   App.xaml.cs
│   AssemblyInfo.cs
│   WinRep-Code.csproj
│   WinRep-Code.csproj.user
│   WinRep-Code.sln
│
├───Utilities
│       BaseViewModel.cs
│       DataTemplate.xaml
│       NavigationService.cs
│       RelayCommand.cs
│
├───ViewModels
│       CustomTweaksVM.cs
│       InstallVM.cs
│       MainWindowVM.cs
│       ScanSettingsVM.cs
│       ScanVM.cs
│       TweaksVM.cs
│
└───Views
        CustomTweaks.xaml
        Install.xaml
        MainWindow.xaml
        Scan.xaml
        ScanSettings.xaml
        Tweaks.xaml

help 🙏🏻
Was this page helpful?