CommunityToolkit / CommunityToolkit/Windows
DataGrid control not working when using XAML islands in a Win32 app
- Dominant language
- C#
- Stars
- 1.1k
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
DataGrid control not working when using XAML islands, adding a DataGrid control to be used with a XAML island from a C# Class Library in a Win32 project wont show up, the code compiles and runs fine except the control is not visible. Is it possible I am missing something ?
For instance adding this in a user control :
```
```
Then in my function which gets called by the Win32 app where I am creating a new window from my SampleWindow which contains the DataGrid results in a blank window.
```
#pragma warning disable IDE0060
public static int ShowWindow(nint args, int sizeBytes)
{
#pragma warning restore IDE0060
if (!Bootstrap.TryInitialize(0x00010007, string.Empty, new PackageVersion(), Bootstrap.InitializeOptions.None, out var hr) &&
!Bootstrap.TryInitialize(0x00010006, string.Empty, new PackageVersion(), Bootstrap.InitializeOptions.OnNoMatch_ShowUI, out hr))
return hr;
if (_app == null)
{
_app = new DummyApp(); // Optional: enables WinUI styles
DispatcherQueueController.CreateOnCurrentThread();
}
var _source = new DesktopWindowXamlSource();
_source.Initialize(Win32Interop.GetWindowIdFromWindow(args));
var window = new SampleWindow();
window.Title = "People Table";
window.Activate();
return 0;
}
```
### Steps to reproduce
```text
1. Add a DataGrid control in a User Control in a C# Class library.
2. Use it in a XAML island in a Win32 app.
3. Control wont show up.
```
### Expected behavior
DataGrid control is visible.
### Screenshots
How it looks when not using XAML island :
How it looks from a XAML island :
### Code Platform
- [ ] UWP
- [x] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK
### Windows Build Number
- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)
### Other Windows Build number
_No response_
### App minimum and target SDK version
- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [x] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [ ] Windows 11, version 22H2 (Build 22000)
- [ ] Other (specify)
### Other SDK version
_No response_
### Visual Studio Version
_No response_
### Visual Studio Build Number
_No response_
### Device form factor
_No response_
### Additional context
_No response_
### Help us help you
Yes, I'd like to be assigned to work on this item.
Contributor guide
Assessment
This issue has not been assessed yet.