I have created a ResourceDictionary file that comes with a .cs file. So after creating the ResourceDictionary file I'm getting an error:
The name 'InitializeComponent' does not exist in the current context.
Below is the XAML file associated with the above file.
I'm using VS2022 17.5.0 Preview 1.0
When I do Project / rt-click / Add / NewItem / .Net Maui ResourceDictionary (XAML)
, this is what gets added to .csproj:
<MauiXaml Update="Dictionary1.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
Note that the Compile
is nested within the MauiXaml
element; it is not a separate Item.
See if your .csproj has TWO separate Items, one for Dictionary1.xaml
, another for Dictionary1.xaml.cs
.
If so, replace those two items, with a combined item as shown above.
(For me, this builds without problem.)
In your case, the .csproj doesn't show MauiXaml
BuildAction?
Replace:
<ItemGroup>
<None Include="Themes\Light.xaml" />
</ItemGroup>
with:
<ItemGroup>
<MauiXaml Update="Themes\Light.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
I don't know whether this should be kept or removed:
<ItemGroup>
<Folder Include="Themes\" />
</ItemGroup>
Leave it in for now.