microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

Question: How to use WinUI with CppWinRT #3712

Closed oldoldman closed 3 years ago

oldoldman commented 4 years ago

I'm trying to use WinUI with my CppWinRT project. I've added the dll in AppxManifest.xml as an in-process server and can succeed to initialize a control (for example SplitButton) in code. But I can not use it in an Xaml page and I found that Xaml runtime will query my application for IXamlType of SplitButton. So I implemented the IXamlMetadataProvider interface and forward the query to XamlControlsXamlMetaDataProvider. But this still does not work (the application crashed). So how to make WinUI work in an Xaml page. Is XamlControlsXamlMetaDataProvider the correct way? Many thank!

JaiganeshKumaran commented 4 years ago

@oldoldman Is this for WinUI 3 desktop or UWP?

oldoldman commented 4 years ago

@oldoldman Is this for WinUI 3 desktop or UWP?

It's WinUI 2.5.0-prerelease.200708003 UWP.

StephenLPeters commented 4 years ago

Did you follow the instructions here: https://docs.microsoft.com/en-us/windows/apps/winui/winui2/getting-started especially around including a reference in your App.xaml?

Its tough to say whats going on from the info provided, but a wild guess you need to include something like this: xmlns:controls="using:Microsoft.UI.Xaml.Controls" in your xaml file.

Otherwise could you please provide a repro application we can use to take a closer look at your issue?

oldoldman commented 4 years ago

@StephenLPeters thanks for reply. Follow the instructions I got some progress : when loading got the following error

0x802B000A Cannot locate resource from 'ms-appx:///Microsoft.UI.Xaml/Themes/19h1_themeresources.xaml'. [Line: 6 Position: 32]

After some searching from this repo, I found 19h1_themeresources.xaml is generated from the project, how can I extract the file from the nupkg? (BTW I'm not using Visual Studio, so , I have to setup all stuff manually (trial and error) , for example, downloading WinUI nupkg and extract what needed and put them in my appx etc.)

ranjeshj commented 4 years ago

@oldoldman curious why you are doing this manually ? If you do file new project and add the nuget package through visual studio does that fail ?

oldoldman commented 3 years ago

I found the missing piece : add a PackageDependency entry to AppxManifest.xml . Many thanks!!!