I've got some text boxes for which i wanted to set the PlaceholderText
property. The text of each box is bound to a property of the underlying view model. Now when setting the placeholder in the XAML like that
<TextBox PlaceholderText="Placeholder" Text={Binding PropertyName} />
i noticed, that the view model's properties are not updated anymore when the text box loses focus. Whereas without placeholder the binding works just fine.
Is this behaviour intended and if are there any workarounds, or do i have to stick to a classic TextBlock
that describes the intended input each box?
Edit: The property does implement INotifyPropertyChanged
and the binding is updated in the view model when no placeholder is set.
PlaceholderText for TextBox does not change the TextBox behavior when it loses focus.
You can try explicitly using the "TwoWay" binding mode for the Text property, instead of the "Default" binding mode.
<TextBox PlaceholderText="Placeholder" Text="{x:Bind PropertyName, Mode=TwoWay}" />
Make sure your View's DataContext is set to your viewmodel, something like below
public MainPage()
{
this.DataContext = new MainViewModel();
this.InitializeComponent();
}
For more information on Binding mode, see to
https://msdn.microsoft.com/en-us/library/windows/apps/mt204783.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With