c# Calling BindingExpression.UpdateSource in UWP MVVM

I would like to make my textboxes only update when the update button is clicked instead of when property is changed. I've set them to UpdateSourceTrigger=Explicit so now I just need the button to call BindingExpression.UpdateSource.

    <TextBox x:Name="textBox_No" HorizontalAlignment="Left" Margin="650,145,0,0" TextWrapping="Wrap" Text="{Binding SelectedItem.Hotel_No, Mode=TwoWay, UpdateSourceTrigger=Explicit}" VerticalAlignment="Top"/>
    <TextBox x:Name="textBox_Name" HorizontalAlignment="Left" Margin="650,218,0,0" TextWrapping="Wrap" Text="{Binding SelectedItem.Name, Mode=TwoWay, UpdateSourceTrigger=Explicit}" VerticalAlignment="Top"/>
    <TextBox x:Name="textBox_Address" HorizontalAlignment="Left" Margin="650,305,0,0" TextWrapping="Wrap" Text="{Binding SelectedItem.Address, Mode=TwoWay, UpdateSourceTrigger=Explicit}" VerticalAlignment="Top"/>
    <Button x:Name="button" Content="Update" HorizontalAlignment="Left" Margin="655,388,0,0" VerticalAlignment="Top" Command="{Binding HotelHandler.UpdateCommand, Mode=TwoWay}"/>

Are there any easy way to call BindingExpression.Updatesource without code-behind? The main reason I'm looking for a non code-behind solution is that I'm learning at school to avoid code-behind at pretty much all cost.

Answers


there are some ways to solve your problem using MVVM pattern, in my experience the best approach when you want to interact with controls indirectly with code behind in the view ( for example MainPage.cs) you must use Behaviors you can attach to the control and all events of this control, create dependency properties etc and you can re use this behaviors with another controls .

Here is an example for Windows 8.1 but it can use it for uwp apps

http://julmar.com/blog/programming/behaviors-in-windows-8-1-store-apps/


Need Your Help

Custom view which inherits checkable from parent

android android-layout android-ui android-custom-view

I've a checkable FrameLayout as root in my ListView. It works very well with multi selection in ListViews.