-1

簡単な作業のようです。MVVMビューからパブリックプロパティ値を渡したいのですが、タイプのプロパティに「バインディング」を設定できません。「バインディング」はにのみ設定できます。依存関係オブジェクトの依存関係プロパティ」エラー。

監視可能なコレクションとアイテムのレンダリングを繰り返しており、テンプレートコードをユーザーコントロールに移動したいと思います。一体どうやってこれを解決できますか????

<local:xIPAddressControl UserControlIPAddressText="{Binding Path=IPAddress, RelativeSource={RelativeSource Mode=Self}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

UserControl

public partial class xIPAddressControl : UserControl
{
    public xIPAddressControl()
    {
        this.InitializeComponent();
    }


    public string UserControlIPAddressText
    {
        get { return this.xIPAddressTextBlock.Text; }
        set { this.xIPAddressTextBlock.Text = value; }
    }
}
4

3 に答える 3

1

UserControlIPAddressTextをCLRプロパティとして定義していますが、依存関係プロパティシステムに登録する必要があります。

DependencyProperty UserControlIPAddressTextProperty = DependencyProperty.Register("UserControlIPADdressText", typeof(string), null);
于 2012-11-08T16:59:15.217 に答える
1

コメントで述べられているように、あなたの財産はそれDependencyPropertyに使用するためにである必要がありますBinding

コードは次のようになります。

        public static readonly DependencyProperty UserControlIPAddressTextProperty=
            DependencyProperty.Register("UserControlIPAddressText",
                                        typeof(string),
                                        typeof(xIPAddressControl));

       public string UserControlIPAddressText
       {
           get { return (string)GetValue(UserControlIPAddressTextProperty); }
           set { SetValue(UserControlIPAddressTextProperty, value); }
       }
于 2012-11-08T23:18:42.157 に答える
1

クレイジーなことに、ユーザーコントロールを間違って設定しようとしていました。次のようにする必要があります。

//this.DataContext = this;

LayoutRoot.DataContext = this;

チュートリアルはこちらです。

于 2012-11-11T23:07:50.880 に答える