仅使用故事板扩展网格而不是内容

时间:2023-02-11 14:18:33

I'm trying to expand a grid using a storyboard, when you click on a button or a picture the grid should then expand, but the problem is that the content inside the grid like the second button I pasted inside the grid is also expanding. Is there someway I can expand the grid without expanding it's content inside. I had this problem with a stack panel, Text box, buttons, frames etc. O and I'm working with a WPf Application and it's XAML

我正在尝试使用故事板扩展网格,当您单击按钮或图片时,网格应该展开,但问题是网格内部的内容(如我粘贴在网格中的第二个按钮)也在扩展。有没有我可以扩展网格而不扩展它的内容。我有一个堆栈面板,文本框,按钮,框架等问题.O和我正在使用WPf应用程序,它是XAML

A simple Xaml code:

一个简单的Xaml代码:

  <Window x:Class="Try.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="Storyboard1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="grid">
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="3.028"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="grid">
                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="106.5"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
        </EventTrigger>
    </Window.Triggers>
  <Grid>
    <Grid x:Name="grid" Margin="75,35,337,107" RenderTransformOrigin="0.5,0.5">
        <Grid.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Grid.RenderTransform>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="White" Offset="0.544"/>
                <GradientStop Color="Black" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
    <Button Content="MyButton" Height="50" Width="50"  />
    </Grid>
</Grid>
</Window>

1 个解决方案

#1


Just give the child elements inside your Grid explicit Heights and Widths.

只需在Grid中显示子元素显式高度和宽度。

<Grid>
    <Button Width="50" Height="50" />
</Grid>

#1


Just give the child elements inside your Grid explicit Heights and Widths.

只需在Grid中显示子元素显式高度和宽度。

<Grid>
    <Button Width="50" Height="50" />
</Grid>