Hi!
I'm new in WPF, so please sorry about my inexperience, I hope, my Question is not too stupid, but I have a problem:
I wrote a simple WPF-UserControl, which has a Lable, an Icon and a TextBox. And of course, the text of the Textbox should be bindable in both directions. It works fine when loading the control, but not, when closing it. I think I forgot to write a peace of code that sends the entered Text back to the Property Text and forces a Changed Event to outside, but I don't know how.
Can anyone help me?
Here is my Code-Behind File:
public partial class TextCtrl : UserControl
{
...
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(TextCtrl),
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTextChanged));
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
private static void OnTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
TextCtrl tx = (TextCtrl)sender;
tx.txtText.Text = eventArgs.NewValue.ToString();
}
In the XAML where I use the Control, I Set a Binding to the Property Text:
<src:TextCtrl Text="{Binding Path=.Strasse}"/>
Strasse is a Property from my ViewModel.
Thanks a lot for helping me, br Alex Hahn