Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to add Grid Splitter in c++/winrt desktop app? #4509

Open
shelllet opened this issue Mar 13, 2021 · 6 comments
Open

Question: How to add Grid Splitter in c++/winrt desktop app? #4509

shelllet opened this issue Mar 13, 2021 · 6 comments
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps area-C++/WinRT Issues related with C++/WinRT experience area-External Not owned by the WinUI team, not actionable in this repository. question team-Markup Issue for the Markup team

Comments

@shelllet
Copy link

I found GridSplitter in Windows Community Toolkit but it dose not support c++/winrt desktop app. what should i do?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 13, 2021
@shelllet shelllet changed the title Question: How do I add Grid Splitter in c++/winrt desktop app? Question: How to add Grid Splitter in c++/winrt desktop app? Mar 13, 2021
@jschwizer99
Copy link

jschwizer99 commented Mar 14, 2021

I also miss the splitter in WinUI using WinRT C++. It is an important design feature for Win32 applications. As far as I know, this functionality is not yet available. It would be nice if this functionality could be added to the roadmap so that we have an idea of when we can expect it.
Meanwhile, I'm using the following workaround by a hidden slider. It's based on https://www.codeproject.com/Tips/1259326/Uwp-Make-a-Resizable-Splitview but needed some changes to get it to work on WinUI as the slider starts jumping around if its own width is updated (WinUI bug?).

<Window
    x:Class="App2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid>
        <Border
            Background="{ThemeResource AppBarBackgroundThemeBrush}"
            VerticalAlignment="Stretch"
            HorizontalAlignment="Right">
            <!-- As WinUI doesn't have a splitter we need a hack.
                 See https://www.codeproject.com/Tips/1259326/Uwp-Make-a-Resizable-Splitview -->
            <!-- In addition the slider starts jumping its value if it is placed inside 
                 the splitview as proposed by above link. This looks like a bug of WinUI.-->
            <Slider
                x:Name="splitterSlider"
                Width="1010"        
                Maximum="1000"
                LargeChange="100"
                SmallChange="100"
                Minimum="0"
                Opacity="0"
                FocusVisualMargin="0"
                FocusVisualPrimaryThickness="0"
                FocusVisualSecondaryThickness="0"
                IsDirectionReversed="true"
                IsThumbToolTipEnabled="False"
                Value="{x:Bind PaneWidth, Mode=TwoWay}"/>
        </Border>
        <SplitView
            IsPaneOpen="True"
            PanePlacement="Right"
            OpenPaneLength="{x:Bind PaneWidth, Mode=OneWay}"
            DisplayMode="Inline">
            <SplitView.Content>
                <Grid
                Margin="0,0,10,0"
                Background="Beige">
                    <TextBlock
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        Text="Left Side"/>
                </Grid>
            </SplitView.Content>
            <SplitView.Pane>
                <Grid
                Background="AliceBlue">
                    <TextBlock
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"                    
                    Text="Right Side"/>
                </Grid>
            </SplitView.Pane>
        </SplitView>
    </Grid>
</Window>

The Width and Maximum value need to track the outer grid width. I'm using a window size event to update their value. If you like proper cursor indicators there is at the moment no way around subclassing to get access to ProtectedCursor. The above workaround and all related quirks indicate that it would be favorable if splitter functionality could be supported by WinUI.

@StephenLPeters
Copy link
Contributor

@michael-hawker FYI. @jevansaks or @kennykerr GridSplitter is defined in a managed DLL, can you implement a winrt projection with a managed binary?

@StephenLPeters StephenLPeters added appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps area-External Not owned by the WinUI team, not actionable in this repository. area-C++/WinRT Issues related with C++/WinRT experience and removed needs-triage Issue needs to be triaged by the area owners labels Mar 16, 2021
@michael-hawker
Copy link
Collaborator

@StephenLPeters @jevansaks there are too many things we'd have to work around to be a Windows Runtime Component, it's too restrictive. I investigated this as part of our 7.0 release and commented on that here: CommunityToolkit/WindowsCommunityToolkit#3145 (comment)

We have been asked on how to include our components using C++ before as well, we have an open issue for 7.1 about writing a sample on how to do this: CommunityToolkit/WindowsCommunityToolkit#3704

I know in the past I've created a C# project, added a Page and referenced Toolkit controls from there and then loaded that page in a C++/CX app (kind of like a XAML Islands type scenario). This of course loads .NET still, but makes it possible to use the controls. The tooling wasn't the best at the time, but it was a few years ago.

GridSplitter wouldn't really work on its own here though, considering it's one of the oldest things in the Toolkit and is part of WPF, it would be a good control for WinUI to look into including in the future.

I guess there's a good question here around how this works in the WinUI 3 world, is there still such a thing as a Windows Runtime Component? I think @marb2000 mentioned there's a transitive concept of something similar still?

@jevansaks
Copy link
Member

WinUI3 doesn't change the landscape of WinRT components like this -- WinRT is the currency for components that can be interoperated across different language boundaries. The thing that might get better is that with Cs/WinRT we have the opportunity to bring C#-implemented components up to parity with native components in terms of all of the limitations that are currently imposed on C# when you try to compile with the WinRT Component flag. But I am guessing that they have only implemented consuming projection support so far and not producing projection support -- but @scott1js would know the state of the world there.

@michael-hawker
Copy link
Collaborator

I've published our C++ sample showing how to use Toolkit components here: https://github.com/CommunityToolkit/Sample-Windows-CppWinRT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps area-C++/WinRT Issues related with C++/WinRT experience area-External Not owned by the WinUI team, not actionable in this repository. question team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

6 participants