In my app, users can click a "New Account" button. The button opens a view where the user can enter information about the new account. I used binding to tie the "Ok" button command to a command in my view model. that all works fine but I can't figure out how to close the "New Account" window since there is no code behind in the view for the ok but click.
Edit (added additional info from answers below):
I'm using C# for the code behind and XAML for the UI.
Here is what i need:
The New Account Dialog to display
The user enters information about the new account in the dialog.
User clicks the "Ok" button.
The dialog closes and the new account is created.
all of this works except the new account dialog doesn't close.
As you can see, the ok button click event is bound to a command in the viewmodel. The code in the viewmodel is executed when the user clicks the button. However, I need the NewAccountDialog to also close when the button is clicked but don't know how to tell the dialog to close from within the viewmodel command and due to binding, there is no code behind in the view where i can call Close().
XAML code the NewAccount view:
<Button
Content="Ok"
Margin="74,95,0,0"
Name="Okbutton"
HorizontalAlignment="Left"
Width="75"
Height="23"
VerticalAlignment="Top"
IsDefault="True"
Command="{Binding OkButtonClickCommand}" />
Code in the NewAccount Viewmodel:
public DelegateCommand<object> OkButtonClickCommand { get; private set; }
private void SetupCommmands()
{
this.OkButtonClickCommand = new DelegateCommand<object>(o =>
{
//Create the new account.
},
o =>
{
return true;
});
}
Code that initiates the process:
public void NewAccount(object obj)
{
this.container.Resolve<NewAccountDialog>().ShowDialog();
}