0

I'm trying to use XamlReader to create a FrameworkElement at runtime in a WinUI3 (WindowsApp) project.

There is documentation on how to do this here.

Unfortunately, the documentation is unclear about what nuget package contains XamlReader. The packages in my app are:

<PackageReference Include="CommunityToolkit.WinUI" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230313.1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />

So which additional package do I need?

Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
  • https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.markup?view=windows-app-sdk-1.3 – demonplus Apr 26 '23 at 07:56

1 Answers1

2

You don't need a NuGet package. You might be missing the namespace:

using Microsoft.UI.Xaml.Markup;

I have a video and a sample app using the XamlReader.

Andrew KeepCoding
  • 7,040
  • 2
  • 14
  • 21
  • Thanx! But no I'm even more confused, because when I had included the Markup namespace yesterday XamlReader was not found...yet today I found it. It's possible I accidentally accepted inclusion of one of those stupid ABI.Microsoft namespaces which frequently gum up WinUI programming. I can't wait until they fix that by hiding what are, in fact, useless namespaces. I appreciate your help, and the example. – Mark Olbert Apr 27 '23 at 04:28
  • 1
    Great! I totally agree. Those ABI.Microsoft namespaces sneaking into (actually, we are letting them) code is very confusing sometimes. – Andrew KeepCoding Apr 27 '23 at 04:35