【问题标题】:How to animate a DataGrid height如何为 DataGrid 高度设置动画
【发布时间】:2015-04-03 18:24:15
【问题描述】:

全部,

我有一个 WPF 数据网格,其中有一个模板列定义如下:

<DataGridTemplateColumn Width="105">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Height="35">
                <Button Style="{StaticResource tableButtonStyle}">
                    <ContentControl/>
                </Button>                   
            </StackPanel>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

按钮样式(仅在用户将鼠标移到特定数据网格行上时显示按钮)如下:

<!-- Disappearing button for tables -->
<Style x:Key="tableButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
    <Setter Property="Visibility" Value="Collapsed"/>
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}},Path=IsMouseOver}" Value="True">
            <Setter Property="Visibility" Value="Visible"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

我想为数据网格的高度设置动画,以便在隐藏按钮时为“X”个单位高,或在显示按钮时为“Y”个单位高。这可以在 xaml 标记中实现吗?

提前致谢!

【问题讨论】:

    标签: wpf wpfdatagrid wpf-animation


    【解决方案1】:

    我不知道在 XAML 中是否有办法做到这一点(我不知道,因为我是 xaml 的新手)。
    但是我会用代码隐藏来做到这一点。我会使用花哨的动画,例如:

    private Storyboard sb=new StoryBoard();
    private DoubleAnimation da=new DoubleAnimation();
    da.From=datagrid.actualHeight;
    da.to=x;
    da.Duration = new Duration(TimeSpan.FromSeconds(0.5));
    Storyboard.SetTargetProperty(da, new PropertyPath(yourDatagrid.HeigthProperty));
    sb.Children.Add(da);
    yourDatagrid.BeginStoryboard(sb);
    

    也许你可以在 ClickEvent 中得到它。 希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2014-12-15
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      相关资源
      最近更新 更多