我们可以将Grid Splitter移动到左侧,就像我们在wpf上点击按钮一样拖动它吗?

时间:2015-08-28 06:05:12

标签: wpf vb.net xaml

  {
            "_id" : ObjectId("55d8a835363ffb2157589145"),
            "like" : [
                {
                    "tlid" : 111,
                    "tlikers" : [
                        "amudibarongo@gmail.com",
                        "harunabarongo@gmail.com"
                    ]
                },
                {
                    "tlid" : 112,
                    "tlikers" : [
                        "amudibarongo@gmail.com",
                        "harunabarongo@gmail.com"
                    ]
                },
                {
                    "tlid" : 113,
                    "tlikers" : [
                        "amudibarongo@gmail.com",
                        "harunabarongo@gmail.com",
                        "jumabarongo@gmial.com"
                    ]
                }
            ],
            "tlikeid" : "amudibarongo@gmail.com"
        }

我想在按钮Click上拖动Grid Splitter。我尝试过Double Animation.StoryBoard,它可以在网格上运行但不适用于网格分割器。

[Initial Image] 1

Dragged Left

Dragged Right

1 个答案:

答案 0 :(得分:5)

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

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>