Gridview 不显示 GTK 中的元素 (Ubuntu)

Gridview don't show elements in GTK (Ubuntu)

在 GTK 上,项目不会像在项目控件中那样显示,尽管它们具有相同的数据源。 我需要一个非常简单的应用程序来使用网格中的多个动态按钮构建。

为什么 GTK 中的 Uno 有这么多错误?

Windows UWP

Ubuntu GTK

XAML

    <Grid>
        <GridView ItemsSource="{Binding GetListCategory}" x:Name="ButtonCategory" SelectionMode="None" IsItemClickEnabled="True" Margin="50,50,0,582">

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>

            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Button Content="{Binding name}" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center"  Height="71" Width="200" Background="WhiteSmoke" Foreground="Black">
                            <Button.Resources>
                                <Style TargetType="Border">
                                    <Setter Property="CornerRadius" Value="50"/>
                                </Style>
                            </Button.Resources>
                        </Button>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>
        
           <ItemsControl ItemsSource="{Binding GetListCategory}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Content="{Binding name}" HorizontalAlignment="Center" VerticalAlignment="Center"      Height="141" Width="148" Background="WhiteSmoke" Foreground="Black"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>

运行 上的控制台输出消息:

max@max-Virtual-Machine:~/Documents/TerminalShow$ dotnet '/home/max/Documents/TerminalShow/TerminalShow.Skia.Gtk.dll' 
fail: Windows.UI.Xaml.Controls.CommandBarFlyout[0]
      The member CommandBarFlyout.CommandBarFlyout() is not implemented in Uno.
fail: Windows.UI.Xaml.Controls.TextCommandBarFlyout[0]
      The member TextCommandBarFlyout.TextCommandBarFlyout() is not implemented in Uno.
warn: Uno.UI.Runtime.Skia.GtkHost[0]
      Loading icon file [/home/max/Documents/TerminalShow/Assets/StoreLogo.png] from Package.appxmanifest file
fail: Windows.UI.Xaml.Media.Animation.PointerUpThemeAnimation[0]
      The member PointerUpThemeAnimation.PointerUpThemeAnimation() is not implemented in Uno.
fail: Windows.UI.Xaml.Media.Animation.PointerDownThemeAnimation[0]
      The member PointerDownThemeAnimation.PointerDownThemeAnimation() is not implemented in Uno.
fail: Windows.UI.Xaml.Media.Animation.AddDeleteThemeTransition[0]
      The member AddDeleteThemeTransition.AddDeleteThemeTransition() is not implemented in Uno.
fail: Windows.UI.Xaml.Media.Animation.ContentThemeTransition[0]
      The member ContentThemeTransition.ContentThemeTransition() is not implemented in Uno.
fail: Windows.UI.Xaml.Media.Animation.ReorderThemeTransition[0]
      The member ReorderThemeTransition.ReorderThemeTransition() is not implemented in Uno.
fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [ScrollViewer] property getter does not exist on type [Windows.UI.Xaml.Controls.GridView]
fail: Windows.UI.Xaml.Controls.WrapGrid[0]
      The member WrapGrid.WrapGrid() is not implemented in Uno.
fail: Windows.UI.Xaml.Media.Animation.PointerUpThemeAnimation[0]
      The member void Begin() is not implemented in Uno.
fail: Uno.UI.DataBinding.BindingPropertyHelper[0]
      The [name] property getter does not exist on type [TerminalShow.ViewModels.MainWindowViewModel]
fail: Windows.UI.Composition.CompositionObject[0]
      The member void CompositionObject.Dispose() is not implemented in Uno.
warn: Windows.UI.Xaml.UIElement[0]
      The BorderThicknessProperty dependency property does not exist on Windows.UI.Xaml.Controls.ItemsPresenter
fail: Windows.UI.Xaml.Controls.ScrollContentPresenter[0]
      The member float ZoomFactor is not implemented in Uno.
fail: Windows.UI.Xaml.Media.Animation.PointerUpThemeAnimation[0]
      The member void Deactivate() is not implemented in Uno.
max@max-Virtual-Machine:~/Documents/TerminalShow$ 

遗憾的是 WrapGrid 尚未在 Uno 平台中实现。相反,默认模板当前使用 WrapPanelItemsWrapGrid 进行布局(取决于平台):

<Setter Property="ItemsPanel">
    <Setter.Value>
        <ItemsPanelTemplate>
            <itemswrapgridpresent:ItemsWrapGrid Orientation="Horizontal" />
            <itemswrapgridnotpresent:WrapPanel />
        </ItemsPanelTemplate>
    </Setter.Value>
</Setter>

您可以使用 platform-specific XAML 使您的自定义 ItemsPanel 声明 Windows 特定,但目前无法在 Uno 中使用 MaximumRowsOrColumns

This PR 将在 ItemsRepeater 控件中添加对 UniformGridLayout 的支持,这将允许您完成类似的布局,而不是使用 GridView.