我希望当我最小化窗口时,StackPanel保持在它的位置上(保持在顶部,不要向下),同时最小化窗口.

100

问题(GIF格式)

GIF Of The Problem

XAML代码

<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>

推荐答案

当窗口最小化时,StackPanel保持在其位置(保持在顶部,不要向下).

问题看起来是ViewBox自动调整大小的原因,您可以try 将Stretch属性设置为Fill以使StackPanel保持在顶部,但在调整窗口大小时会使Canvas项形状发生变化.

另一种方法是通过将VerticalAlignment设置为top,将ViewBox固定在父容器的顶部.

Csharp相关问答推荐

System.Text.Json:反序列化返回为空数组的字典时出错

如何使用Microsoft Curve API从搜索的文件中获取内容(文本)?

我们应该如何在IHostedService中使用按请求的GbContent实例?

无法使用并行库并行化我的代码

使用GeneratedComInterfaceProperty的.NET 8 COM类对于VB 6/SYS或ALEViewer不可见

下拉图片点击MudBlazor

程序集.加载从exe的异常

一种安全的方式来存储SSH凭证(MAUI/C#应用程序)

Entity Framework Core 8 dbcontext—无法以多对多关系添加某些行'

WPF Windows初始化正在锁定. Net 8中分离的线程

==和Tuple对象的相等<>

. net依赖注入如何避免服务类中的新

更改执行目录

为什么AggregateException的Catch块不足以处理取消?

如何在CSharp中将json字符串转换为DataTable?

什么类型的对象存储在大对象堆(LOH)中

如何实现有条件的自定义Json转换器隐藏属性

将C#类导入到PowerShell

流畅的验证--如何为属性重用规则?

在使用.NET EF Core DbContext属性之前,是否应使用null判断