哪个控件可以拉伸?

huangapple go评论60阅读模式
英文:

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.

&lt;!-- area a and b --&gt;
        &lt;Grid Background=&quot;White&quot; HorizontalAlignment=&quot;Left&quot; CornerRadius=&quot;12&quot; Margin=&quot;8&quot;&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
                &lt;ColumnDefinition Width=&quot;500&quot;/&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Grid.RowDefinitions&gt;
                &lt;RowDefinition Height=&quot;Auto&quot; /&gt;
            &lt;/Grid.RowDefinitions&gt;
            &lt;!-- area a --&gt;
            &lt;StackPanel Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot; Margin=&quot;10&quot;&gt;
                &lt;StackPanel Orientation=&quot;Horizontal&quot; Background=&quot;LightGoldenrodYellow&quot;&gt;
                    ...
                &lt;/StackPanel&gt;
                &lt;StackPanel Orientation=&quot;Horizontal&quot; Background=&quot;AntiqueWhite&quot;&gt;
                    ...
                &lt;/StackPanel&gt;
                &lt;dxg:GridControl ItemsSource=&quot;{x:Bind ViewModel.a, Mode=TwoWay}&quot; SelectedItems=&quot;{x:Bind ViewModel.b, Mode=TwoWay}&quot; AutoGenerateColumns=&quot;False&quot; IsFilterEnabled=&quot;False&quot; ShowAutoFilterRow=&quot;False&quot; SelectionMode=&quot;Row&quot; SelectionChanged=&quot;grid_SelectionChanged&quot;&gt;
                    &lt;dxg:GridControl.Columns&gt;
                        ...
                    &lt;/dxg:GridControl.Columns&gt;
                &lt;/dxg:GridControl&gt;
            &lt;/StackPanel&gt;
            &lt;!-- area b --&gt;
            &lt;StackPanel Grid.Row=&quot;0&quot; Grid.Column=&quot;1&quot; Margin=&quot;10&quot;&gt;
                &lt;StackPanel Background=&quot;LightGoldenrodYellow&quot;&gt;
                    ..
                &lt;/StackPanel&gt;
                &lt;StackPanel  Orientation=&quot;Horizontal&quot; Background=&quot;AntiqueWhite&quot;&gt;
                      ..      
                &lt;/StackPanel&gt;
                &lt;dxg:GridControl ItemsSource=&quot;{x:Bind ViewModel.Tasks, Mode=TwoWay}&quot; AutoGenerateColumns=&quot;False&quot; IsFilterEnabled=&quot;False&quot; SelectionMode=&quot;Row&quot;&gt;
                    &lt;dxg:GridControl.Columns&gt;
                        ..
                    &lt;/dxg:GridControl.Columns&gt;
                &lt;/dxg:GridControl&gt;
            &lt;/StackPanel&gt;
        &lt;/Grid&gt;

答案1

得分: 0

你可以使用 CommunitToolkit.WinUI.UI.Controls.Layout NuGet 包中的 GridSplitter

&lt;Window
    x:Class=&quot;GridSplitterExample.MainWindow&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:local=&quot;using:GridSplitterExample&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    xmlns:toolkit=&quot;using:CommunityToolkit.WinUI.UI.Controls&quot;
    mc:Ignorable=&quot;d&quot;&gt;
    &lt;Grid ColumnDefinitions=&quot;*,Auto,*&quot;&gt;
        &lt;Grid Grid.Column=&quot;0&quot;&gt;
            &lt;TextBlock Text=&quot;左列&quot; /&gt;
        &lt;/Grid&gt;
        &lt;toolkit:GridSplitter Grid.Column=&quot;1&quot; /&gt;
        &lt;Grid Grid.Column=&quot;2&quot;&gt;
            &lt;TextBlock Text=&quot;右列&quot; /&gt;
        &lt;/Grid&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;

请注意,我已将 "Left Column" 和 "Right Column" 翻译为中文。

英文:

You can use the GridSplitter from the CommunitToolkit.WinUI.UI.Controls.Layout NuGet package.

&lt;Window
    x:Class=&quot;GridSplitterExample.MainWindow&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:local=&quot;using:GridSplitterExample&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    xmlns:toolkit=&quot;using:CommunityToolkit.WinUI.UI.Controls&quot;
    mc:Ignorable=&quot;d&quot;&gt;
    &lt;Grid ColumnDefinitions=&quot;*,Auto,*&quot;&gt;
        &lt;Grid Grid.Column=&quot;0&quot;&gt;
            &lt;TextBlock Text=&quot;Left Column&quot; /&gt;
        &lt;/Grid&gt;
        &lt;toolkit:GridSplitter Grid.Column=&quot;1&quot; /&gt;
        &lt;Grid Grid.Column=&quot;2&quot;&gt;
            &lt;TextBlock Text=&quot;Right Column&quot; /&gt;
        &lt;/Grid&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;

huangapple
  • 本文由 发表于 2023年5月21日 16:31:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定