HI,
I have two usercontrols UC1 (with a single text box ) and UC2 (with a single textBlock) and both the user controls are placed in the MAinwindow. UC1 and UC2 has its own corresponding View models (UC1VM and UC2VM).
My requirement is, when I type something in my UC1 textbox, I want it to be dispalyed in the UC2 textblock. so waht I did is had a text property in my UC1VM.
string myText; public string MyText { get { return myText; } set { myText = value; PropertyChanged(this, new PropertyChangedEventArgs("MyText")); } }
IN my UC2VM I had a Attached DP as show belwo (UC2VM inherits DependencyObject).
public static DependencyProperty StringDetailProperty = DependencyProperty.RegisterAttached("StringDetail", typeof(string), typeof(UC2VM), new PropertyMetadata(new PropertyChangedCallback(xyz))); public static void SetStringDetail(UIElement element, string value) { element.SetValue(StringDetailProperty, value); } public static string GetStringDetail(UIElement element) { return (string)element.GetValue(StringDetailProperty); } static void xyz(DependencyObject depObj, DependencyPropertyChangedEventArgs args) { ..... }
My mainWindow XAML as follows.
<Window x:Class...<ucs:UC1 x:Name="uc1" ></ucs:UC1><ucs:UC2 ucs1:UC2VM.StringDetail="{Binding ElementName=uc1, Path=MyText}" ></ucs:UC2></Window>
Whenever I change the textbox value in my UC1, the "MyText" property gets updated, but hte function xyz written in UC2VM is not getting hit. kindly help. Not interested in using any frameworks like MVVMLight or prism etc... Like to know how ti can be achieved without using the frameworks.
Aslo one more question. Can I write a DP in my code behind file of a User control as per mvvm.
Thanks,
Sanjay.