CommunityToolkit / Windows

Collection of controls for WinUI 2, WinUI 3, and Uno Platform developers. Simplifies and demonstrates common developer tasks building experiences for Windows with .NET.
https://aka.ms/windowstoolkitdocs
Other
596 stars 74 forks source link

GridSplitter invisible when added in C# (just 'Control' in Live Visual Tree), but visible when added in xaml #502

Closed TRadigk closed 2 months ago

TRadigk commented 2 months ago

Describe the bug

Adding a GridSplitter in C# will not let it render. Adding it in XAML though will let it render. Also: When added in XAML it is a resolved component in the Live Visual Tree, while when added in C# it is just "Control":

Added in XAML: grafik

MainWindow XAML:

<Window
    x:Class="CommunityToolkitTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CommunityToolkitTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    mc:Ignorable="d">

    <Grid ColumnSpacing="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Border BorderThickness="1" Grid.Row="0" BorderBrush="Green" Grid.Column="0" />
        <Border BorderThickness="1" Grid.Row="0" BorderBrush="Red" Grid.Column="1" />

        <controls:GridSplitter Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left"
                               ResizeBehavior="BasedOnAlignment"
                               ResizeDirection="Auto">
        </controls:GridSplitter>
    </Grid>
</Window>

MainWindow C#:

public sealed partial class MainWindow : Window
{
    public MainWindow()
    {
        this.InitializeComponent();
    }
}

Added in C#: grafik

MainWindow XAML:

<Window
    x:Class="CommunityToolkitTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CommunityToolkitTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    mc:Ignorable="d">

</Window>

MainWindow C#:

public sealed partial class MainWindow : Window
{
    public MainWindow()
    {
        this.InitializeComponent();

        var grid = new Grid
        {
            ColumnSpacing = 10
        };
        grid.ColumnDefinitions.Add(new ColumnDefinition());
        grid.ColumnDefinitions.Add(new ColumnDefinition());

        var gridSplitter = new GridSplitter
        {
            ResizeBehavior = GridSplitter.GridResizeBehavior.BasedOnAlignment,
            ResizeDirection = GridSplitter.GridResizeDirection.Auto,
            HorizontalAlignment = HorizontalAlignment.Left,
        };

        var borderLeft = new Border
        {
            BorderThickness = new Thickness(1),
            BorderBrush = new SolidColorBrush(Colors.Green)
        };
        var borderRight = new Border
        {
            BorderThickness = new Thickness(1),
            BorderBrush = new SolidColorBrush(Colors.Red)
        };
        grid.Children.Add(borderRight);
        grid.Children.Add(borderLeft);
        Grid.SetColumn(borderRight, 1);
        Grid.SetColumn(borderLeft, 0);
        Grid.SetColumn(gridSplitter, 1);
        grid.Children.Add(gridSplitter);
        Content = grid;
    }
}

Steps to reproduce

1. Create new Winui Desktop App unpackaged.
2. Ensure Windows App SDK package version is 1.6.240829007
3. Ensure <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
4. Add nuget package CommunityToolkit.WinUI.Controls.Sizers 8.1.240821
5. Use code from issue to reproduce

Expected behavior

The GridSplitter is visible when added in C#, like it is visible when added in XAML.

Screenshots

No response

Code Platform

Windows Build Number

Other Windows Build number

Windows 11 24H2 26100.1591

App minimum and target SDK version

Other SDK version

No response

Visual Studio Version

2022, Preview

Visual Studio Build Number

Version 17.12.0 Preview 1.0

Device form factor

Desktop

Additional context

No response

Help us help you

No, I'm unable to contribute a solution.

TRadigk commented 2 months ago

Additional investigations: Other controls like a radial Gauge can be added without any problems. But the grid splitter can't even be added with 8.0.230907 or 8.0.240109: grafik

michael-hawker commented 2 months ago

Duplicate of #273