【发布时间】:2014-12-07 21:12:05
【问题描述】:
我的 XAML 中有一个包含一些用户控件的统一网格。每个 UserControl 都带有一个 Ellipse。 O 尝试访问Ellipse添加动画但无法获取uniformgrid的孩子。
谢谢。
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:当我尝试以这种方式访问孩子(最后一行)时是不可能的。 Checkerboard 是 UI 统一网格的名称,我不知道如何访问渲染动画。当我尝试从名称 checkerBoard 渲染到 uniformgrid 时,这是在这个 uiElement 上工作,但我想访问包含在 checkerBoard 上的椭圆(子级):
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()));
}
【问题讨论】:
标签: c# wpf get children uielement