gpt4 book ai didi

wpf - 我们可以移动 Grid Splitter On Left 就像我们在 wpf 中单击按钮时拖动它一样吗?

转载 作者:行者123 更新时间:2023-12-01 12:32:31 35 4
gpt4 key购买 nike

    <Grid>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="◄" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Content="►" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</StackPanel>

<Grid Height="245">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--Declaring Label-->
<DockPanel LastChildFill="False" Background="Yellow">
<Label Content="Left" Grid.Column="0" DockPanel.Dock="Left" />
</DockPanel>
<!--Splitter Code-->
<GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Grid.Column="1" ResizeDirection="Columns"
Background="Black" ResizeBehavior="PreviousAndNext" Width="10"/>
<!--Declaring Label-->
<Label Content="Right" Grid.Column="2" Background="Pink"/>
</Grid>
</StackPanel>
</Grid>

我想在单击按钮时拖动 Grid Splitter。我尝试了 Double Animation.StoryBoard,它适用于网格但不适用于网格拆分器。

[Initial Image] 1

Dragged Left

Dragged Right

最佳答案

您必须调整网格列的大小,而不是 gridsplitter。

private void BtnLeft_Click(object sender, RoutedEventArgs e)
{
MyGrid.ColumnDefinitions[0].Width = new GridLength(100);
}
<Grid x:Name="MyGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Label Content="Left" Background="LightBlue" />
<GridSplitter Grid.Column="1" Width="10" ResizeBehavior="PreviousAndNext" />
<Label Content="Right" Background="LightGoldenrodYellow" Grid.Column="2" />

<Button Content="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BtnLeft_Click" />
</Grid>

关于wpf - 我们可以移动 Grid Splitter On Left 就像我们在 wpf 中单击按钮时拖动它一样吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32264330/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com