2012-01-05 12 views
0

デザイナーは、XAMLとして構築されたときに正常に動作するXAML VisualStateコードをいくつか作成しました。このXAMLをCode Behindに変換するのは私の仕事です。これはChildWindowを継承したカスタムTemplateコントロールで、このChildWindowに対するすべての子UserControlsであるさまざまな「ウィンドウ」間のアニメーションを作成します。私はアニメーションのいずれかを実行したときに、私はすべてのコードを書かれている動的コントロールのコードにXAMLを変換する

は、しかし、私は、Silverlightはというエラーを取得「targetproperty解決することはできません 『(UIElement.Projectionを)。(PlaneProjection.RotationY)』」

このorigional XAML

<VisualState x:Name="AtRegistration"> 
    <Storyboard> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="WindowContentPresenter" Storyboard.TargetProperty="(Content).Children[0].(UIElement.Visibility)"> 
      <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Collapsed" /> 
     </ObjectAnimationUsingKeyFrames> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="WindowContentPresenter" Storyboard.TargetProperty="(Content).Children[1].(UIElement.Visibility)"> 
      <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="Visible" /> 
     </ObjectAnimationUsingKeyFrames> 
    </Storyboard> 
</VisualState> 
<VisualState x:Name="AtLogin"> 
    <Storyboard> 
     ... XAML omitted ... 
    </Storyboard> 
</VisualState> 
<VisualStateGroup.Transitions> 
    <VisualTransition From="AtRegistration" To="AtLogin"> 
     <Storyboard> 
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentRoot" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)"> 
       ... XAML OMITTED ... 
      </DoubleAnimationUsingKeyFrames> 
      ... XAML OMITTED ... 
     </Storyboard> 
    </VisualTransition> 
    <VisualTransition From="AtLogin" To="AtRegistration"> 
     ... XAML OMITTED ... 
    </VisualTransition> 
</VisualStateGroup.Transitions> 

です ... XAML OMITTED ... XAML上記

ザ・私は、コードを書くときただし、これにはない、正常に動作します。コードで間違っていると思っていますが、見つけられません。私のテンプレートXAMLで

public override void OnApplyTemplate() 
{ 
base.OnApplyTemplate(); 

var content = (ContentPresenter)GetTemplateChild("WindowContentPresenter"); 
m_contentRoot = (Grid)GetTemplateChild("ContentRoot"); 

var grid = (Grid)GetTemplateChild("Root"); 

if(grid != null) 
{ 
    // Create the state group 
    var animGroup = new VisualStateGroup(); 
    animGroup.SetValue(NameProperty, "AnimationStates"); 

    var grp = VisualStateManager.GetVisualStateGroups(grid); 
    grp.Add(animGroup); 

    for(int i = 0; i < MultiControls.Count; i++) 
    { 
     var state = new VisualState(); 
     state.SetValue(NameProperty, GetControlName(i)); 
     animGroup.States.Add(state); 

     state.Storyboard = new Storyboard(); 

     // create an animation for each of the multi controls 
     for(int j = 0; j < MultiControls.Count; j ++) 
     { 
      // Create the storyboard 
      var anim = new ObjectAnimationUsingKeyFrames(); 
      Storyboard.SetTarget(state.Storyboard, content); 
      anim.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath(string.Format("(Content).Children[{0}].(UIElement.Visibility)", j))); 
      anim.KeyFrames.Add(new DiscreteObjectKeyFrame 
            { 
             KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0)), 
             Value = j == i ? Visibility.Visible : Visibility.Collapsed 
            }); 

      state.Storyboard.Children.Add(anim); 

      // Don't create a transition to and from the other states. 
      if(i == j) 
       continue; 

      // Create the Transition 
      var trans = new VisualTransition { From = GetControlName(j), To = GetControlName(i) }; 
      animGroup.Transitions.Add(trans); 
      trans.Storyboard = new Storyboard(); 

      var dbl = new DoubleAnimationUsingKeyFrames { BeginTime = TimeSpan.FromSeconds(0) }; 
      Storyboard.SetTarget(trans.Storyboard, m_contentRoot); 
      dbl.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")); 
      trans.Storyboard.Children.Add(dbl); 

      ... CODE OMITTED ... 
     } 
    } 
} 
} 

私はこれを持っている:

<Grid x:Name="Overlay" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0" Background="{TemplateBinding OverlayBrush}" Opacity="{TemplateBinding OverlayOpacity}"/> 
<Grid x:Name="ContentRoot" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" RenderTransformOrigin="0.5,0.5" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"> 
<Grid.Projection> 
    <PlaneProjection/> 
</Grid.Projection> 

は君たち/ギャルは、任意のアイデアを持っていますか?

ありがとうございました。

+0

var dblをストーリーボードの子供に追加して、それを設定しようとしましたか? – evasilchenko

+0

私は試みました:var dbl = new DoubleAnim .....(); trans.Storyboard.Children.Add(dbl);そして、そのプロパティをすべて設定しても問題は解決しませんでした。 – guyaton

+0

"UIElement.Projection。(PlaneProjection.RotationY)"を読み込むためにPropertyPath文字列を変更してみてください。 - 最初のかっこの削除を確認してください。基本的には、ソースとxamlの中でこのパスを定義するのが異なるため、そのパスでプレイする必要があります。 – evasilchenko

答えて

0

Storyboard.SetTargetの2番目のパラメータは、投影であり、m_contentrootではありません。パスに指定する必要があるのは、すべて「RotationY」です。

関連する問題