It seems to me as if you are asking 'How can I bind a property of a UserControl
to a property of a view model'. You really should read the basics of data binding before asking these questions here. For future reference, please read the Data Binding Overview page at MSDN.
Given that you still have not provided enough information, I will assume that your property is of type string
. In this case, your view model will need a standard property of type string
to bind to your DependencyProperty
... this property must implement the INotifyPropertyChanged
interface:
private string viewModelProperty = string.Empty;
public string ViewModelProperty
{
get { return viewModelProperty; }
set { viewModelProperty = value; NotifyPropertyChanged("ViewModelProperty"); } }
}
Make sure that the DataContext
of the Window
that has your UserControl
in it is set to an instance of the view model class:
In the MainWindow
constructor:
DataContext = new ViewModelClass();
Or in XAML:
<DataTemplate DataType="{x:Type ViewModels:ViewModelClass}">
<Views:yourView />
</DataTemplate>
Then you simply bind with a Two Way
binding:
<YourNamespace:MyUserControl
TBBroadcastLocation="{Binding ViewModelProperty, Mode=TwoWay}" />