Skip to content

DataGrid control not working when using XAML islands in a Win32 app #725

@Iordan-Iulian-Bogdan

Description

@Iordan-Iulian-Bogdan

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 :

        <controls:DataGrid x:Name="nameGrid"
                   AutoGenerateColumns="False"
                   Margin="0,0,0,10"
                   Width="600"
                   HeadersVisibility="Column"
                   GridLinesVisibility="Horizontal"
                   IsReadOnly="True">
            <controls:DataGrid.Columns>
                <controls:DataGridTextColumn Header="ID" Binding="{Binding Id}" Width="SizeToHeader"/>
                <controls:DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" Width="*"/>
                <controls:DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" Width="*"/>
                <controls:DataGridTextColumn Header="Address" Binding="{Binding Address}" Width="2*"/>
            </controls:DataGrid.Columns>
        </controls:DataGrid>

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

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 :

Image

How it looks from a XAML island :

Image

Code Platform

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions