调整大小的窗口时,如何保持stackpanel?

发布于 2025-02-09 09:03:48 字数 2993 浏览 3 评论 0 原文

我希望当我最小化窗户时,stackpanel停留在其位置(停留在顶部,不要倒下),而窗户则最小化。

I'm not looking for a direct answer, I just want to find some direction, some help on where to start.

Problem (GIF Format)

GIF Of The Problem

XAML Code

<Grid Padding="25">
    <NavigationView PaneDisplayMode="Top">
        <NavigationView.MenuItems>
            <NavigationViewItem Content="Test" IsSelected="False" Icon="PreviewLink" />
        </NavigationView.MenuItems>

        <Viewbox StretchDirection="Both" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="1111">
            <StackPanel Width="1400" Height="1000" Margin="85, 0, 0, 150">

                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="-1099, 50, 10, 10">

                    <Canvas Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">
                        <TextBlock FontSize="40" Padding="0, 35, 300, 0" Margin="115, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>

                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="-420, -190, 10, 10">


                    <Canvas Opacity="50" Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">
                        <TextBlock FontSize="40" Padding="0, 35, 300, 0" Margin="115, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>


                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="260, -190, 10, 10">

                    <Canvas Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">
                        <TextBlock FontSize="40" Padding="0, 35, 300, 0" Margin="115, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>


                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="940, -190, 10, 10">

                    <Canvas Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">

                        <TextBlock FontSize="35" Padding="0, 35, 300, 0" Margin="60, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>
            </StackPanel>
        </Viewbox>

    </NavigationView>

</Grid>

I would like that when I minimize the window, the StackPanel stays on its position (Stay on top, don't go under) while the window is minimized.

I'm not looking for a direct answer, I just want to find some direction, some help on where to start.

Problem (GIF Format)

GIF Of The Problem

XAML Code

<Grid Padding="25">
    <NavigationView PaneDisplayMode="Top">
        <NavigationView.MenuItems>
            <NavigationViewItem Content="Test" IsSelected="False" Icon="PreviewLink" />
        </NavigationView.MenuItems>

        <Viewbox StretchDirection="Both" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="1111">
            <StackPanel Width="1400" Height="1000" Margin="85, 0, 0, 150">

                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="-1099, 50, 10, 10">

                    <Canvas Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">
                        <TextBlock FontSize="40" Padding="0, 35, 300, 0" Margin="115, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>

                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="-420, -190, 10, 10">


                    <Canvas Opacity="50" Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">
                        <TextBlock FontSize="40" Padding="0, 35, 300, 0" Margin="115, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>


                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="260, -190, 10, 10">

                    <Canvas Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">
                        <TextBlock FontSize="40" Padding="0, 35, 300, 0" Margin="115, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>


                <Border CornerRadius="25" Background="#1D1D1D" Height="180" Width="300" Margin="940, -190, 10, 10">

                    <Canvas Background="#1D1D1D" Width="250" Height="200" HorizontalAlignment="Left">

                        <TextBlock FontSize="35" Padding="0, 35, 300, 0" Margin="60, 35, 0, 0" Text="Test"
                                   Foreground="#1D1D1D"
                                    />
                    </Canvas>
                </Border>
            </StackPanel>
        </Viewbox>

    </NavigationView>

</Grid>

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

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

发布评论

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

评论(1

神仙妹妹 2025-02-16 09:03:48

stackpanel停留在其位置(停留在顶部,不要倒下)。

这个问题看起来自动调整大小原因,您可以尝试设置 stretch 属性为 fill 使StackPanel停留在顶部,但它将制作 Canvas 调整窗口大小时,项目形状会更改。

另一种方法是通过将垂直段设置为顶部的fix ViewBox。

the StackPanel stays on its position (Stay on top, don't go under) while the window is minimized.

The problem looks ViewBox auto resize cause, you could try to set Stretch property as Fill to make StackPanel stays on the top, but it will make Canvas item shape change when resize the window.

The other way is fix ViewBox on the top of parent container by setting up VerticalAlignment as top.

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