c# - WPF Grid 向右对齐并覆盖整列
问题描述
我有一个包含两列的网格,首先,有一个画布,其次,有一个由一些按钮组成的网格,依此类推。我想让第二列中的网格成为一个可打开的菜单,这样,当单击按钮时,它会移动到右侧并缩小自身。问题是我无法强制网格覆盖整个列并一次向右对齐。
当我将网格向右对齐时,可打开的菜单可以正常工作,但是该列仅被网格的一半占用,因此画布和列之间存在不想要的空间。
<Grid x:Name ="GridMenu" HorizontalAlignment="Right" Grid.Column="1">
另一方面,当对齐为默认(或拉伸)时
<Grid x:Name ="GridMenu" HorizontalAlignment="Stretch" Grid.Column="1">,
然后触发后
<Window.Resources>
<Storyboard x:Key="MenuOpen">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
<EasingDoubleKeyFrame KeyTime="0" Value="70"></EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="200"></EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="MenuClose">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
<EasingDoubleKeyFrame KeyTime="0" Value="200"></EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="70"></EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="OpenMenuButton">
<BeginStoryboard Storyboard="{StaticResource MenuOpen}"></BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="CloseMenuButton">
<BeginStoryboard Storyboard="{StaticResource MenuClose}"></BeginStoryboard>
</EventTrigger>
</Window.Triggers>
(EasingDoubleKeyFrame 的值只是临时的)将第一列中的网格移动到中心而不是将其移动到右侧。 网格对齐到中心而不是右侧
解决方案
推荐阅读
- c# - 如何从 CosmosDB 中的现有容器中获取带有索引的 ContainerProperties
- java - 如何从具有多个纬度和经度坐标的 JSON 文件创建谷歌地图标记
- visual-studio - 尝试重新安装包时的 NuGet 循环依赖
- spring-kafka - Kafka 消费者无法使用 Spring Boot 2.2.0.M4 连接到 localhost:9092 以外的代理
- eclipse - 如何在 JUnit 中为 Eclipse E4 插件项目使用依赖注入
- javascript - 我无法制作一个不确定长度的 javascript 列表,仅在分配某些属性时才显示
- sql - 在 SELECT 中对季度数据进行分组并计算 SUM
- twilio - 为什么 Twilio Flex Worker 属性会自动更改?具体来说, Roles 属性
- mysql - 使用选择信息输出文件
- r - R中混合多个图形的轴标题对齐