c# - WPF 网格列 def auto 总是从右边剪裁
问题描述
我有一个 WPF 应用程序,它有一个网格,其中 2 列设置为 * 和 auto。问题是当我减小窗口的大小时,第二列中的子项从右侧而不是左侧被剪裁。我希望它们从左侧剪辑,因为我已将水平对齐设置为右侧。有没有办法我们可以从左边剪掉第二列元素?
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="60"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<DockPanel HorizontalAlignment="Right" Grid.Column="1">
<Button Click="Button_Click" Content="click me" Width="150" DockPanel.Dock="Right" />
<Label Content="abcdef" Width="200" DockPanel.Dock="Right" />
<Label x:Name="mLog"/>
</DockPanel>
<Button Click="Button_Click" DockPanel.Dock="Right" Content="click me" Width="150"/>
<Label Content="abcdef" Width="200" DockPanel.Dock="Right"/>
</Grid>
</Window>
解决方案
而不是这个:
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="60"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<DockPanel HorizontalAlignment="Right" Grid.Column="1">
<Button Click="Button_Click" Content="click me" Width="150" DockPanel.Dock="Right" />
<Label Content="abcdef" Width="200" DockPanel.Dock="Right" />
<Label x:Name="mLog"/>
</DockPanel>
<Button Click="Button_Click" DockPanel.Dock="Right" Content="click me" Width="150"/>
<Label Content="abcdef" Width="200" DockPanel.Dock="Right"/>
</Grid>
</Window>
尝试这个:
<Window x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="60"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<DockPanel HorizontalAlignment="Right" Grid.Column="1">
<Button Click="Button_Click" Content="click me" Width="150" DockPanel.Dock="Right" />
<Label Content="abcdef" Width="200" DockPanel.Dock="Right" />
<Label x:Name="mLog"/>
</DockPanel>
<Button Click="Button_Click" DockPanel.Dock="Right" Content="click me"/>
<Label Content="abcdef" Width="200" DockPanel.Dock="Right"/>
</Grid>
</Window>
我删除了最后一个按钮宽度属性。
输出:
推荐阅读
- database - 基于工作流的系统的数据库设计
- javascript - 如何从 js 脚本文件中调用 laravel 路由?
- python - 从子字符串中提取的映射运算符
- data-structures - 数据结构的使用
- android - 从谷歌地图android中的可见区域获取邮政编码列表
- scala - 从镶木地板文件读取时出现异常
- php - 我可以在 laravel 的变量数据库中使用 2 foreach 吗?
- java-11 - 字符串到对象的转换 - 在 Java 11 中不起作用
- android-mediaplayer - 使用 Android Studio 的 MediaPlayer
- c# - SaveChangesAsync 方法不保存更改(环境问题)