2017-07-18 15 views
2

私は問題がある、私は(Windows 10のタイルのような)タイルという名前のコントロールを作成します。 このタイルは、Silverlightの投影クラスのように、投影クラスを使用して回転3Dをシミュレートします。WPF PropertyPath on Customコントロール

我々はこのような基本プロジェクション・クラスがあります。

abstract public class Projection 
    : FrameworkElement 
{ 
    static public readonly DependencyProperty RotationZProperty = DependencyProperty.Register(
      nameof(RotationZ), 
      typeof(double), 
      typeof(Projection), 
      new UIPropertyMetadata(0.0, OnRotationChanged)); 

    static public readonly DependencyProperty RotationYProperty = DependencyProperty.Register(
      nameof(RotationY), 
      typeof(double), 
      typeof(Projection), 
      new UIPropertyMetadata(0.0, OnRotationChanged)); 

    static public readonly DependencyProperty RotationXProperty = DependencyProperty.Register(
      nameof(RotationX), 
      typeof(double), 
      typeof(Projection), 
      new UIPropertyMetadata(0.0, OnRotationChanged)); 

public double RotationZ 
{ 
    get { return this.GetValue<double>(RotationZProperty); } 
    set { SetValue(RotationZProperty, value); } 
} 

public double RotationY 
{ 
    get { return this.GetValue<double>(RotationYProperty); } 
    set { SetValue(RotationYProperty, value); } 
} 

public double RotationX 
{ 
    get { return this.GetValue<double>(RotationXProperty); } 
    set { SetValue(RotationXProperty, value); } 
} 

public FrameworkElement Child 
{ 
    get; 
    set; 
} 

static private void OnRotationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
     { 
      if (d is Projection pl) 
      { 
       pl.OnRotationChanged(); 
      } 
     } 

     private void OnRotationChanged() 
     { 
      // Some code 
     }} 

After that, we have the PlaneProjectionClass : 

    [ContentProperty("Child")] 
    sealed public class PlaneProjection 
     : Projection 
    { 
    } 

をタイルクラスは型の投影の依存関係プロパティを使用します。

 public class Tile 
    { 
    static public readonly DependencyProperty PlaneProjectionProperty = DependencyProperty.Register(
      nameof(Projection), 
      typeof(Projection), 
      typeof(Tile), 
      new UIPropertyMetadata()); 

public Projection Projection 
     { 
      get { return (Projection)GetValue(PlaneProjectionProperty); } 
      private set { SetValue(PlaneProjectionProperty, value); } 
     } 

     override public void OnApplyTemplate() 
     { 
      Projection = GetTemplateChild("PART_Projection") as Projection; 
     } 
    } 

のでXAMLのために、私たちはのControlTemplateでこれを持っている:

<controls:PlaneProjection x:Name="PART_PlaneProjection"> 
    <Border> 
    <Grid> 
     <!-- Some design --> 
    </Grid> 
    </Border> 
</controls:PlaneProjection> 

今、私は平面飛行をアニメーション化したいと思います。

だから私は、ストーリーボードを作成してれるrotationXと投影アニメーション:

static public void CreateAnimation(Tile tile) 
{ 
    Storyboard.SetTarget(anim, tile); 
    Storyboard.SetTargetProperty(doubleAnim, new PropertyPath("(Tile.Projection).(PlaneProjection.RotationX")); 
} 

しかし、デバッグ時に、私はこのエラーを持っている:プロパティのパス上のプロパティのすべての参照を解決できません「(Tile.Projection )。私は間違い:(カスタムコントロール上のPropertyPathを使用して上の任意のアイデアを理解していない

(PlaneProjection.RotationX)?

答えて

2

PR依存の命名規則に従わないクラスタイルでProjectionプロパティオペラ

次のようになります。

public static readonly DependencyProperty PlaneProjectionProperty = 
    DependencyProperty.Register(nameof(PlaneProjection), typeof(Projection), typeof(Tile)); 

public Projection PlaneProjection 
{ 
    get { return (Projection)GetValue(PlaneProjectionProperty); } 
    private set { SetValue(PlaneProjectionProperty, value); } 
} 

プロパティパスは、単純にこのようになります:

Storyboard.SetTargetProperty(anim, new PropertyPath("PlaneProjection.RotationX")); 

あなたも、ストーリーボードを必要としません。ただ、注意点として

tile.PlaneProjection.BeginAnimation(Projection.RotationXProperty, anim); 

を呼び出して、民間のセッターは、依存関係プロパティは読み取り専用になりません。詳細は、Read-Only Dependency Propertiesを参照してください。