2011-11-14 7 views
3

添付プロパティで動作を作成しています。行動は、グリッドに接続する必要があります。このプロパティが表示されないのはなぜですか?添付可能なプロパティが見つかりません。

public class InteractionsBehavior : Behavior<Grid> 
{ 
    public static readonly DependencyProperty ContainerProperty = 
     DependencyProperty.RegisterAttached("Container", typeof(Grid), typeof(Grid), new PropertyMetadata(null)); 

    public static readonly DependencyProperty InteractionsProviderProperty = 
     DependencyProperty.RegisterAttached("InteractionsProvider", typeof(IInteractionsProvider), typeof(Grid), new PropertyMetadata(null, OnInteractionsProviderPropertyChanged)); 

    public Grid Container 
    { 
     get { return GetValue(ContainerProperty) as Grid; } 
     set { this.SetValue(ContainerProperty, value); } 
    } 

    public IInteractionsProvider InteractionsProvider 
    { 
     get { return GetValue(InteractionsProviderProperty) as IInteractionsProvider; } 
     set { this.SetValue(InteractionsProviderProperty, value); } 
    } 

今、私はこのようなXAMLを書いているとき、私はエラーを取得:

<Grid Background="White" x:Name="LayoutRoot" 
      Behaviors:InteractionsBehavior.InteractionsProvider="{Binding InteractionsProvider}"> 

Error 4 The property 'InteractionsProvider' does not exist on the type 'Grid' in the XML namespace 'clr-namespace:Infrastructure.Behaviors;assembly=Infrastructure.SL'. C:\MainPage.xaml 11 11 Controls.SL.Test

Error 1 The attachable property 'InteractionsProvider' was not found in type 'InteractionsBehavior'. C:\MainPage.xaml 11 11 Controls.SL.Test

答えて

3

あなたは唯一の所有」(添付されるために利用可能であることを指定しました")。InteractionsBehavior

+0

私は自分の投稿を編集しました。同じ問題です。同じエラーが発生します。クラスそのものに何か問題があるのだろうか?行動はどういう意味ですか?? – katit

+0

@katitこれは表現の振る舞いです。もしあなたがそれを使っているなら、おそらく、添付されたプロパティは必要ありません。通常は、動作または添付プロパティのいずれかを使用します。添付プロパティを使用する場合は、get/setアクセサの仕様を修正する必要があります。http://msdn.microsoft.com/en-us/library/ms749011.aspx –

+0

異なる行動タイプ。今は "状態"を持っているように見えるので、表現の振る舞いは私にはもっと適しているようです。あなたは私の質問に答えた、私はあなたが表現の振る舞いを書く方法についての良いチュートリアルへのポインタを持っていれば感謝します – katit

1

問題はである(...またはGridのクラス階層内のいくつかの基本クラスを使用します)

public static readonly DependencyProperty InteractionsProviderProperty = 
     DependencyProperty.RegisterAttached("InteractionsProvider", typeof(IInteractionsProvider), typeof(Grid), new PropertyMetadata(null, OnInteractionsProviderPropertyChanged)); 

:あなたはグリッドにこれを割り当てることができるようにしたい場合は、RegisterAttachedラインへの変更添付されたプロパティの宣言。添付プロパティは、名前、型、所有者の種類、およびプロパティのメタデータの4つの部分を持ちます。 InteractionsProviderプロパティがGrid型によって所有されている(したがって提供されている)ことを指定しています。実際にはそうではありません。所有者タイプ(3番目のパラメータ)をtypeof(InteractionsBehavior)(添付プロパティを宣言したクラス)に変更し、プロパティの代わりに静的なget/setメソッドに切り替えます(依存プロパティではなく、添付プロパティを使用しているため)それはあなたが期待するようにすべて動作するはずです。

+0

マイク、私はリードの答えをマーク。実際には、命名規則に従ってSetInteractionsProviderとGetInteractionsProviderを追加したときに機能し始めました。しかし、このコードの「静的」な性質は私のためには機能していないようですが、私は式の振る舞いについて調べる必要があります – katit

+0

このリンクを試してください:http://blogs.msdn.com/b/expression/archive/2009/ 03/23/an-introduction-to-behaviors-triggers-and-actions.aspx –

関連する問題