Verwenden der DataGrid-Klasse (CommunityToolkit.WinUI.UI.Controls) in einer XAML-Insel aus einer C#-KlassenbibliothekC++

Programme in C++. Entwicklerforum
Anonymous
 Verwenden der DataGrid-Klasse (CommunityToolkit.WinUI.UI.Controls) in einer XAML-Insel aus einer C#-Klassenbibliothek

Post by Anonymous »

Ich habe das folgende Setup: Ich zeige WinUI3-Elemente aus einer C#-Klassenbibliothek in einer Win32-C++-App mithilfe von

Code: Select all

public static int ShowWindow(nint args, int sizeBytes)
#pragma warning restore IDE0060 // Remove unused parameter
{
// Initialize WinAppSDK 1.6 or 1.7
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 3 styles
DispatcherQueueController.CreateOnCurrentThread();
}

var _source = new DesktopWindowXamlSource();
_source.Initialize(Win32Interop.GetWindowIdFromWindow(args));

var window = new Microsoft.UI.Xaml.Window();

var sampleData = new List
{
new Person { Name = "Alice", Age = 30 },
new Person { Name = "Bob", Age = 25 },
new Person { Name = "Charlie", Age = 35 }
};

var dataGrid = new CommunityToolkit.WinUI.UI.Controls.DataGrid
{
AutoGenerateColumns = true,
ItemsSource = sampleData,
Margin = new Thickness(20)
};

var grid = new Microsoft.UI.Xaml.Controls.Grid
{
Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.White)
};
grid.Children.Add(dataGrid);

window.Content = grid;
window.Activate();

return 0;
}
Es wird kompiliert und ausgeführt, außer dass das DataGrid nicht angezeigt wird, das Fenster, das ich erstelle, leer ist, derselbe Code funktioniert und das DataGrid korrekt anzeigt, wenn ich dies in einer C#-WinUI3-App mache. Irgendeine Idee, warum?
Das fragliche Beispielprojekt finden Sie hier.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post