繁体   English   中英

如何访问UIElement的子级以添加动画

[英]How to access children of UIElement to add animation

我在XAML中有一个统一网格,其中包含一些UserControl。 每个UserControl都有一个椭圆。 O尝试访问“椭圆”以添加动画,但无法获得统一网格的子级。

谢谢。

XAML:

<Grid Grid.Column="1" Grid.Row="2">
        <Separator Opacity="0" Height="20"/>

        <!-- Checkerboard -->
        <!-- ************ -->
        <UniformGrid Name="checkerboard" Height="540" Width="540" HorizontalAlignment="Center" VerticalAlignment="Center"/>

XAML.CS(添加子项)-> Cell是一个对象用户控件:

public void addCellToBoard(CellControl cell)
        {
            checkerboard.Children.Add(cell);
        }

Other.cs:当我尝试向孩子们(最后一行)进门时,这种方式是不可能的。 棋盘格是UI统一网格的名称,我不知道如何渲染动画。 当我尝试从名称checkerBoard转换为Uniformgrid时,这在此uiElement上起作用,但是我想访问checkerBoard上包含的Ellipse(子级):

private void animation(CellControl cell)
        {
            Storyboard storyboard = new Storyboard();
            TimeSpan duration = new TimeSpan(0, 0, 1);
            DoubleAnimation animation = new DoubleAnimation();
            animation.From = 0.0;
            animation.To = 1.0;
            animation.Duration = new Duration(duration);
            Storyboard.SetTargetName(animation, othelloWindow.checkerboard.Name);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Control.OpacityProperty));
            storyboard.Children.Add(animation);
            storyboard.Begin(othelloWindow.checkerboard.FindName(cell.ellipse.Name.ToString()));

        } 

这似乎就是您所需要的:

void animation(CellControl cell)
{
    var animation = new DoubleAnimation(0.0, 1.0, TimeSpan.FromSeconds(1.0));

    cell.ellipse.BeginAnimation(UIElement.OpacityProperty, animation);
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM