2014-12-07 7 views
0

내 XAML에 UserControl이 포함 된 uniformgrid가 있습니다. 각 UserControl은 타원을 나타냅니다. 애니메이션을 추가하려면 Ellipse에 액세스하려고 시도하지만 uniformgrid의 자식을 가져 오는 것은 불가능합니다.UIElement의 자식에 액세스하여 애니메이션을 추가하는 방법

감사합니다.

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 (아이를 추가) -> 셀 객체 사용자 컨트롤입니다 :

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

Other.cs : 내가 (마지막으로 아이들에게 ACESS 할 때 라인)이 방법으로 불가능합니다. Checkerboard는 UI uniformgrid의 이름입니다. 애니메이션을 렌더링하는 방법을 알지 못합니다. 내가 이름 바둑판에서 uniformgrid을 rendre 할 때, 즉이 UIElement에에 일하고있어하지만 난 타원 (어린이)에 액세스 할 바둑판에 포함 된 :

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())); 

     } 

답변

0

이 당신이 필요로하는 모든 것 같습니다 :

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

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

대단히 감사합니다. :) – syca