英文:
Which control can I stretch?
问题
给定一个具有两列的网格。如何让用户能够更改每列的宽度?他应该能够在较小的显示器上最大化一列的宽度。
<!-- 区域 a 和 b -->
<Grid Background="White" HorizontalAlignment="Left" CornerRadius="12" Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- 区域 a -->
<StackPanel Grid.Row="0" Grid.Column="0" Margin="10">
<StackPanel Orientation="Horizontal" Background="LightGoldenrodYellow">
...
</StackPanel>
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
...
</StackPanel>
<dxg:GridControl ItemsSource="{x:Bind ViewModel.a, Mode=TwoWay}" SelectedItems="{x:Bind ViewModel.b, Mode=TwoWay}" AutoGenerateColumns="False" IsFilterEnabled="False" ShowAutoFilterRow="False" SelectionMode="Row" SelectionChanged="grid_SelectionChanged">
<dxg:GridControl.Columns>
...
</dxg:GridControl.Columns>
</dxg:GridControl>
</StackPanel>
<!-- 区域 b -->
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
<StackPanel Background="LightGoldenrodYellow">
..
</StackPanel>
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
..
</StackPanel>
<dxg:GridControl ItemsSource="{x:Bind ViewModel.Tasks, Mode=TwoWay}" AutoGenerateColumns="False" IsFilterEnabled="False" SelectionMode="Row">
<dxg:GridControl.Columns>
..
</dxg:GridControl.Columns>
</dxg:GridControl>
</StackPanel>
</Grid>
请注意,这是XML代码的翻译部分。如果您需要更多帮助或有其他问题,请随时提出。
英文:
Given is a grid with two columns. How can I give the user the ability to change the width of each column? He should be able to maximize the width of one column on a smaler display.
<!-- area a and b -->
<Grid Background="White" HorizontalAlignment="Left" CornerRadius="12" Margin="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- area a -->
<StackPanel Grid.Row="0" Grid.Column="0" Margin="10">
<StackPanel Orientation="Horizontal" Background="LightGoldenrodYellow">
...
</StackPanel>
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
...
</StackPanel>
<dxg:GridControl ItemsSource="{x:Bind ViewModel.a, Mode=TwoWay}" SelectedItems="{x:Bind ViewModel.b, Mode=TwoWay}" AutoGenerateColumns="False" IsFilterEnabled="False" ShowAutoFilterRow="False" SelectionMode="Row" SelectionChanged="grid_SelectionChanged">
<dxg:GridControl.Columns>
...
</dxg:GridControl.Columns>
</dxg:GridControl>
</StackPanel>
<!-- area b -->
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
<StackPanel Background="LightGoldenrodYellow">
..
</StackPanel>
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
..
</StackPanel>
<dxg:GridControl ItemsSource="{x:Bind ViewModel.Tasks, Mode=TwoWay}" AutoGenerateColumns="False" IsFilterEnabled="False" SelectionMode="Row">
<dxg:GridControl.Columns>
..
</dxg:GridControl.Columns>
</dxg:GridControl>
</StackPanel>
</Grid>
答案1
得分: 0
你可以使用 CommunitToolkit.WinUI.UI.Controls.Layout NuGet 包中的 GridSplitter
。
<Window
x:Class="GridSplitterExample.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:local="using:GridSplitterExample"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<Grid ColumnDefinitions="*,Auto,*">
<Grid Grid.Column="0">
<TextBlock Text="左列" />
</Grid>
<toolkit:GridSplitter Grid.Column="1" />
<Grid Grid.Column="2">
<TextBlock Text="右列" />
</Grid>
</Grid>
</Window>
请注意,我已将 "Left Column" 和 "Right Column" 翻译为中文。
英文:
You can use the GridSplitter
from the CommunitToolkit.WinUI.UI.Controls.Layout NuGet package.
<Window
x:Class="GridSplitterExample.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:local="using:GridSplitterExample"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
mc:Ignorable="d">
<Grid ColumnDefinitions="*,Auto,*">
<Grid Grid.Column="0">
<TextBlock Text="Left Column" />
</Grid>
<toolkit:GridSplitter Grid.Column="1" />
<Grid Grid.Column="2">
<TextBlock Text="Right Column" />
</Grid>
</Grid>
</Window>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论