microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.34k stars 675 forks source link

Question: Couldn't xaml host controls from the WinUI 3 library #7029

Open Ajith-GS opened 2 years ago

Ajith-GS commented 2 years ago

According to WinUI roadmap table, which is available in the following link https://github.com/microsoft/microsoft-ui-xaml/blob/main/docs/roadmap.md the XAML Islands is available as experimental feature in Windows App SDK 1.0. I have been trying to modernize an existing Win32 app with WinUI 3 ( used template : [Experimental] Blank App (WinUI 3 in UWP) , C++ ) by using the steps described in the following page https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands-cpp. But when replacing namespace Windows with Microsoft, the app.base.h file generating build errors like, 'TypeName': is not a member of 'winrt::Microsoft::UI::Xaml::Interop' (compiling source file App.cpp). So, what is the proper way for hosting controls from the WinUI 3 library using XAML Islands ? and is any document available for hosting controls from the WinUI 3 library with XAML Islands support ?

ojhad commented 2 years ago

TypeName and TypeKind are still under the Windows namespace. Can you try updating this and see if that resolves your issues?

Ajith-GS commented 2 years ago

When replacing namespace Microsoft with Windows, the XamlTypeInfo.g.cpp file generate build errors like, 'Markup': is not a member of 'winrt::Windows::UI::Xaml'
'IXamlMetadataProvider': is not a member of 'winrt::Windows::UI::Xaml' 'winrt::Windows::Foundation::Collections::IVector': 'IXamlMetadataProvider' is not a valid template type argument for parameter 'T'

castorix commented 2 years ago

The links you posted are for hosting UWP controls, not WinUI 3 controls XAML Islands is not ready : under-consideration Some XAML controls can be used in C++/Win32 apps like the test I did in this thread but there are limitations and it is just a workaround

Ajith-GS commented 2 years ago

Little bit confused here. So it is not available as an experimental feature in Windows App SDK 1.0, is it? But the WinUI roadmap table ( https://github.com/microsoft/microsoft-ui-xaml/blob/main/docs/roadmap.md ) shows it is available.

michalleptuch commented 2 years ago

I would like to update my .NET apps to the newest .NET Core and then use WindowsAppSDK and XAML Islands but the future for XAML Islands is unclear. I see that MS team want to focus on XAML Islands only for C++ 😞

ojhad commented 2 years ago

@bpulliam is there documentation you can point to for Xaml Islands?

DeveloperInUK commented 1 year ago

Hi, could anyone give me an update on using Xaml island with WinUI3 please? We have an old MFC based application and would like to update it to use WinUI3. If it is already available to use, could you let me know the web page explaining how to use it (i.e. example code) please? If it is not available, could you let me know when it will be available please?

Ajith-GS commented 1 year ago

Is there any sample or document available for hosting WinUI3 custom controls in an existing Win32 application as a part of modernization? XAML hosting APIs are available in the latest Windows App SDK 1.4 , but there is no documentation for how we can host the custom control.

castorix commented 1 year ago

Is there any sample or document available for hosting WinUI3 custom controls in an existing Win32 application as a part of modernization? XAML hosting APIs are available in the latest Windows App SDK 1.4 , but there is no documentation for how we can host the custom control.

As posted in some other threads (by DarranRowe or myself), a basic way is with Microsoft.UI.Xaml.Hosting.DesktopWindowXamlSource (like in old C++/Win32/UWP XAML Islands) I tested in C# WinForms and WPF, but atm I have a problem in WPF (it only works once the window is completely built, but I probably forgot something...)

Ajith-GS commented 1 year ago

Is there any sample or document available for hosting WinUI3 custom controls in an existing Win32 application as a part of modernization? XAML hosting APIs are available in the latest Windows App SDK 1.4 , but there is no documentation for how we can host the custom control.

As posted in some other threads (by DarranRowe or myself), a basic way is with Microsoft.UI.Xaml.Hosting.DesktopWindowXamlSource (like in old C++/Win32/UWP XAML Islands) I tested in C# WinForms and WPF, but atm I have a problem in WPF (it only works once the window is completely built, but I probably forgot something...) Hi, But when following the steps mentioned in the link https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands-cpp, it throwing memory access violation exception in the following line:  auto interop = _desktopWindowXamlSource.as<IDesktopWindowXamlSourceNative>(); I also made changes to make the project unpackaged and added code for bootstrap initialization. Is there anything that I am missing? Could you please provide a sample application? I am working with a C++ application, but for reference, WinForms is fine. Thank you.

castorix commented 1 year ago

Could you please provide a sample application? I am working with a C++ application, but for reference, WinForms is fine.

I just uploaded a test sample in WinForms/C# : CSharp_WinUI3_DesktopWindowXamlSource (I cannot do it in C++ because it takes hours to compile in C++/WinRT on my old PC...)

khoabui1412 commented 1 year ago

@castorix, with your wpf source, can winUI3 element stretch following windows resizing? I see that has black region when do resizing.

castorix commented 1 year ago

@castorix, with your wpf source, can winUI3 element stretch following windows resizing? I see that has black region when do resizing.

Did you resize the container window ? (I did not resize it in my test on sizing event/message) (Microsoft.UI.Content.DesktopChildSiteBridge Win32 class or SiteBridge)

khoabui1412 commented 1 year ago

yes, I receive sizechanged message and resize the container window, but it also has black region when resize

castorix commented 1 year ago

If I just add a TextBlock inside a blue Grid, are you talking about the default black background that can be seen when size is increased ? :

XAML_Islands_Resize

khoabui1412 commented 1 year ago

No, the black region will overlap WinUI element when resize... But today, I cannot reproduce anymore :((. Anyway, thank you.