Search code examples
c#xamluwpwinui-3winui

Where do I find XamlReader?


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?


Solution

  • 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.