I have a window with multiple textbox inputs. When I click Edit it loads in the current user and if i make changes then decide to cancel it doesn't remove the changes on cancel.
If I try to edit the same person again the changes I made previously are still in the input fields.
This is how I call the edit window
<Button x:Uid="Button_EditCommand" Margin="0,0,2,0" Command="{Binding Path=EditProviderCommand}" Style="{StaticResource btnCustom}" MinWidth="75" Content="Save" Visibility="{Binding Path=IsEditing, Converter={StaticResource VisibilityConverter}}" />
This then calls the box and this is my cancel method
CancelCommand = new RelayCommand(Cancel);
public ICommand CancelCommand { get; private set; }
private void Cancel()
{
Provider = null;
OnRequestClose();
}
The cancel method is shared with the Add method. When I type in the Add and click cancel it clears all changes. How do I get it to clear out the edited fields instead of binding them to the binding?
TextBoxes:
<TextBox x:Uid="TextBox_1" Grid.Column="1" Grid.Row="0" Tag="{Binding Path=FirstNameLabel, Source={StaticResource Clientization}}" Style="{StaticResource EditTextBox}" MaxLength="35"
Text="{Binding Path=Provider.FirstName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_2" Grid.Column="2" Grid.Row="0" Tag="Middle" MinWidth="75" Style="{StaticResource EditTextBox}" MaxLength="30"
Text="{Binding Path=Provider.MiddleName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_3" Grid.Column="1" Grid.Row="1" Tag="{Binding Path=LastNameLabel, Source={StaticResource Clientization}}" Style="{StaticResource EditTextBox}" MaxLength="60"
Text="{Binding Path=Provider.LastName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_4" Grid.Column="2" Grid.Row="1" Tag="Suffix" Style="{StaticResource EditTextBox}" MaxLength="20"
Text="{Binding Path=Provider.Suffix, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_5" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" Tag="List Name*" Style="{StaticResource EditTextBox}" MaxLength="160"
Text="{Binding Path=Provider.ListName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_6" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="3" Tag="NPI*" Style="{StaticResource EditTextBox}" MaxLength="80"
Visibility="{Binding Path=HideNpi, Source={StaticResource Clientization}, Converter={StaticResource TernaryConverter}, ConverterParameter='True ? Collapsed : Visible'}"
Text="{Binding Path=Provider.NPI, UpdateSourceTrigger=PropertyChanged}"/>
Update:
My copy of provider
public AddEditProviderDialogViewModel(IProviderRepository providerRepository, IMedListProvider medListProvider,
Provider provider, bool isEditing)
: this(providerRepository, medListProvider, provider)
{
_isEditing = isEditing;
Provider editProvider = new Provider()
{
FirstName = provider.FirstName,
LastName = provider.LastName,
Prefix = provider.Prefix,
Suffix = provider.Suffix,
ListName = provider.ListName,
NPI = provider.NPI,
OrgName = provider.OrgName,
Address1 = provider.Address1,
Address2 = provider.Address2,
City = provider.City,
State = provider.State,
Zip = provider.Zip,
EmailAddress = provider.EmailAddress,
Phone1Type = provider.Phone1Type,
Phone2Type = provider.Phone2Type,
Phone1 = provider.Phone1,
Phone2 = provider.Phone2
};