在wpf中转换1面板后删除2面板之间的空间

时间:2016-11-07 10:59:11

标签: c# wpf xaml

我正在改变左侧菜单(红色),但在我转换后,右侧面板不是完整空间。我该如何删除它?

  

当左侧菜单转换完成时,我希望右侧面板已满,并且没有   白色空间。

这是我的代码:

Xaml文件

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Storyboard x:Key="TestStoryboard">
            <DoubleAnimation Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)" From="0"
                         To="-50"/>
        </Storyboard>
    </Window.Resources>

    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <DockPanel Grid.Column="0" Name="MyGrid" Background="Red">

            <DockPanel.RenderTransform>
                <TranslateTransform X="0" Y="0"/>
            </DockPanel.RenderTransform>

            <Button VerticalAlignment="Top" 
            HorizontalAlignment="Left"
            Margin="10" 
            Content="Click"
            Click="Button_Click" />
        </DockPanel>

        <DockPanel Background="Gold" Grid.Column="1" Name="test">

        </DockPanel>

    </Grid>
</Window>

xaml.cs文件:

namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }

            private void showTopMenu_MouseEnter(object sender, MouseEventArgs e)
            {

            }

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                Storyboard myStoryboard = (Storyboard)this.Resources["TestStoryboard"];

                TranslateTransform myTranslate = new TranslateTransform();
                myTranslate.X = 50;
                myTranslate.Y = 0;
                MyGrid.RenderTransform = myTranslate;

                Storyboard.SetTarget(myStoryboard.Children.ElementAt(0) as DoubleAnimation, MyGrid);
                //Storyboard.SetTarget(myStoryboard.Children.ElementAt(1) as DoubleAnimation, MyGrid);

                myStoryboard.Begin();
            }
        }
    }

enter image description here

0 个答案:

没有答案