[英]How to access children of UIElement to add animation
i have in my XAML an uniformgrid who contain some UserControl. 我在XAML中有一个统一网格,其中包含一些UserControl。 Each UserControl avec an Ellipse. 每个UserControl都有一个椭圆。 O try to access to the Ellipse to add animation but impossible to get children of the uniformgrid. O尝试访问“椭圆”以添加动画,但无法获得统一网格的子级。
Thank you. 谢谢。
XAML : 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 (add children) -> Cell is an object user control: XAML.CS(添加子项)-> Cell是一个对象用户控件:
public void addCellToBoard(CellControl cell)
{
checkerboard.Children.Add(cell);
}
Other.cs : when i try to acess to the children (last line) not possible at this way. Other.cs:当我尝试向孩子们(最后一行)进门时,这种方式是不可能的。 Checkerboard is the name of the UI uniformgrid, i don't know how to acess to render the animation. 棋盘格是UI统一网格的名称,我不知道如何渲染动画。 When i try to rendre to uniformgrid from name checkerBoard, that's working on this uiElement but i want to access to the Ellipse (children) included on the checkerBoard : 当我尝试从名称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()));
}
This seems to be all you need: 这似乎就是您所需要的:
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.