[英]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.