C# WPF - 退出全屏后添加子项是将其添加到原来位置的右侧

发布于 2024-11-14 09:08:05 字数 1353 浏览 3 评论 0原文

我刚刚开始 WPF,所以我只是在学习,但在制作 UIElement 全屏时遇到了问题。

我有一个水平 StackPanel,里面有 2 个 UIElement:另外 2 个 StackPanel,左边的一个包含一个 3dViewport 和另一个 StackPanel按钮,右侧的按钮包含一个由矩形组成的垂直堆栈面板。

当我将左侧 StackPanel 全屏显示时,它工作正常,我将其从外部 StackPanel 中删除,并将其添加为窗口的内容,如下代码隐藏所示

private void mediaFullscreen(object sender, RoutedEventArgs e)
    {
        containerPanel.Children.Remove(leftPanel);
        this.Content = leftPanel;

        this.WindowState = WindowState.Maximized;
        this.WindowStyle = WindowStyle.None;

        isFullscreen = true;
    }

:问题是,当我退出全屏时,因为我将左侧 StackPanel 重新添加到外部 StackPanel,它被添加到列表/树的末尾,因此看起来的权利(前)右侧 StackPanel(其中包含 矩形),而不是像全屏之前那样位于左侧。这是我用来退出全屏的代码:

private void keyDownHandler(object sender, KeyEventArgs e)
    {
        if (isFullscreen)
        {
            this.Content = Root;
            containerPanel.Children.Add(leftPanel);

            this.WindowState = WindowState.Normal;
            this.WindowStyle = WindowStyle.SingleBorderWindow;

            isFullscreen = false;
        }
    }

有没有办法在某个位置添加一个子级,以便(前)左侧 StackPanel 再次放在左侧,而不是在(前)之后右边的StackPanel 吗?

感谢您抽出时间,

Infinitifizz

I'm just starting WPF so am just learning but I've ran into a problem when making a UIElement fullscreen.

I have a horizontal StackPanel with 2 UIElements inside: 2 more StackPanels, the one on the left contains a 3dViewport and another StackPanel of Buttons and the one on the right contains a vertical stackpanel of Rectangles.

When I make the left StackPanel fullscreen, it works fine, I remove it from the outer StackPanel and add it as the content of the Window as shown below in the codebehind:

private void mediaFullscreen(object sender, RoutedEventArgs e)
    {
        containerPanel.Children.Remove(leftPanel);
        this.Content = leftPanel;

        this.WindowState = WindowState.Maximized;
        this.WindowStyle = WindowStyle.None;

        isFullscreen = true;
    }

The problem is, when I exit fullscreen, because I re-add the left StackPanel to the outer StackPanel, it is added at the end of the list/tree and so appears to the right of the (former) right StackPanel (which holds the Rectangles) rather than on the left as it was before fullscreen. Here is the code I use to exit fullscreen:

private void keyDownHandler(object sender, KeyEventArgs e)
    {
        if (isFullscreen)
        {
            this.Content = Root;
            containerPanel.Children.Add(leftPanel);

            this.WindowState = WindowState.Normal;
            this.WindowStyle = WindowStyle.SingleBorderWindow;

            isFullscreen = false;
        }
    }

Is there a way to add a child at a certain position so that the (former) left StackPanel gets put on the left again rather than after the (former) right StackPanel on the right?

Thanks for your time,

Infinitifizz

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆啦不做梦 2024-11-21 09:08:05

好的,刚刚排序,很抱歉发布这个问题,但我会在这里为可能遇到同样问题的其他人回答。

当退出全屏时,我没有使用:containerPanel.Children.Add(leftPanel);,而是使用:containerPanel.Children.Insert(0, leftPanel);将 leftPanel 元素插入为 containerPanel 的第一个索引,因此它位于左侧,就像全屏之前一样。

抱歉浪费您的时间,

InfinitiFizz

Okay just sorted it, sorry for posting the question but I'll answer it here for anyone else who might have the same problem.

Instead of using:containerPanel.Children.Add(leftPanel); when coming out of fullscreen, I've used: containerPanel.Children.Insert(0, leftPanel); which inserts the leftPanel element as the first index of the containerPanel, therefore it is at the left like it used to be before going fullscreen.

Sorry for wasting your time,

InfinitiFizz

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文