How to empty a textbox in MVVM environment UWP C#

Viewed 29

I have several textboxes that are filled when adding a new record. If I cancel the adding before saving the record, only the textboxes are filled with content. I want to empty these boxes when canceling the action. I have a button to cancel the action. This button is bound to the Viewmodel on the Click action. I considered to use the code behind for this clearing action but I see no way of reaching the code behind from the viewmodel in My MVVM approach

<TextBox
        Header="Coach"
        PlaceholderText="naam coach"
        Margin="8,8,16,8"
        MinWidth="200"
        x:Name="NaamTextBox"
        Text="{x:Bind Viewmodel.NewCoach.Naam, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox
        Header="Telefoon"
        PlaceholderText="telefoon"
        Margin="8,8,16,8"
        MinWidth="200"
        x:Name="TelefoonTextBox" 
        Text="{x:Bind Viewmodel.NewCoach.Telefoon, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<AppBarButton x:Name="DeleteNewRecord" Click="{x:Bind Viewmodel.DeleteNewRecord}" Icon="Cancel"/>
<AppBarButton x:Name="SaveNewRecord" Click="{x:Bind Viewmodel.SaveNewRecord}" Icon="Save"/>

I considered to use the code behind for this clearing action but I see no way of reaching the code behind from the viewmodel in my MVVM approach. Is there a simple way to clear data on a form before it's used by the viewmodel?

0 Answers
Related