UserControl
「のプロパティをビューモデルのプロパティにバインドするにはどうすればよいですか」と尋ねているように思えます。ここでこれらの質問をする前に、データ バインディングの基本を読む必要があります。今後の参考のために、MSDNのData Binding Overviewページをお読みください。
まだ十分な情報が提供されていないため、プロパティのタイプはstring
. この場合、ビュー モデルには、string
バインドする型の標準プロパティが必要になりますDependencyProperty
。このプロパティはインターフェイスを実装する必要があります。INotifyPropertyChanged
private string viewModelProperty = string.Empty;
public string ViewModelProperty
{
get { return viewModelProperty; }
set { viewModelProperty = value; NotifyPropertyChanged("ViewModelProperty"); } }
}
あなたが含まれているDataContext
のがビュー モデル クラスのインスタンスに設定されていることを確認します。Window
UserControl
MainWindow
コンストラクターで:
DataContext = new ViewModelClass();
または XAML で:
<DataTemplate DataType="{x:Type ViewModels:ViewModelClass}">
<Views:yourView />
</DataTemplate>
Two Way
次に、バインディングでバインドするだけです。
<YourNamespace:MyUserControl
TBBroadcastLocation="{Binding ViewModelProperty, Mode=TwoWay}" />