Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ajith-GS opened this issue Apr 27, 2022 · 16 comments
Open

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

Ajith-GS opened this issue Apr 27, 2022 · 16 comments
Labels
question team-Reach Issue for the Reach team

Comments

@Ajith-GS
Copy link

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 ?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Apr 27, 2022
@ojhad
Copy link
Contributor

ojhad commented Apr 28, 2022

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

@ojhad ojhad added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners labels Apr 28, 2022
@Ajith-GS
Copy link
Author

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'

@ghost ghost added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Apr 29, 2022
@castorix
Copy link

castorix commented Apr 29, 2022

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
Copy link
Author

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
Copy link

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 ojhad added the team-Reach Issue for the Reach team label May 4, 2022
@ojhad
Copy link
Contributor

ojhad commented May 4, 2022

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

@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Dec 6, 2022
@DeveloperInUK
Copy link

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
Copy link
Author

Ajith-GS commented Sep 4, 2023

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
Copy link

castorix commented Sep 4, 2023

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
Copy link
Author

Ajith-GS commented Sep 4, 2023

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
Copy link

castorix commented Sep 5, 2023

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
Copy link

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

@castorix
Copy link

castorix commented Oct 5, 2023

@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
Copy link

khoabui1412 commented Oct 6, 2023

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

@castorix
Copy link

castorix commented Oct 6, 2023

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests

7 participants