still shown DialogService until error exists in user input and dont press Cancel
-
Hi, I included DialogService in my Window to call other view which contains User input values What I need is to prevent closing this dialog until input are validated.
_roleViewModel = new Role_ViewModel(eTypeOperation);
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
var cancelCommand = new UICommand
{
Id = MessageBoxResult.Cancel,
Caption = Properties.Resources.CstCancel,
IsCancel = true,
IsDefault = false,
};
RoleService.ShowDialog(new List { createCommand, cancelCommand }, Properties.Resources.CstNewRole, _roleViewModel);private IDialogService RoleService
{
get { return GetService("RoleServiceDialog"); }
}the CanCreateRole control the state of Button "OK" regarding input user But What I need is to : When click OK button , we should check data (user input) if it is ok we return and close the DialogService otherwise we should display messagebox and stay on this DialogService (don't close) until press "Cancel" Thank you
-
Hi, I included DialogService in my Window to call other view which contains User input values What I need is to prevent closing this dialog until input are validated.
_roleViewModel = new Role_ViewModel(eTypeOperation);
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
var cancelCommand = new UICommand
{
Id = MessageBoxResult.Cancel,
Caption = Properties.Resources.CstCancel,
IsCancel = true,
IsDefault = false,
};
RoleService.ShowDialog(new List { createCommand, cancelCommand }, Properties.Resources.CstNewRole, _roleViewModel);private IDialogService RoleService
{
get { return GetService("RoleServiceDialog"); }
}the CanCreateRole control the state of Button "OK" regarding input user But What I need is to : When click OK button , we should check data (user input) if it is ok we return and close the DialogService otherwise we should display messagebox and stay on this DialogService (don't close) until press "Cancel" Thank you
In your
CanCreateRole
method, validate the input, and returnfalse
if the input is not valid. In yourCreateRole
method, callCanCreateRole
to validate the input, and if it's not valid, don't close the dialog.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
In your
CanCreateRole
method, validate the input, and returnfalse
if the input is not valid. In yourCreateRole
method, callCanCreateRole
to validate the input, and if it's not valid, don't close the dialog.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
But this did'nt solve my problem :) because what I need is : - let user enter some data (if no data => the button still disabled related to
CanCreateRole
- when there is data click on Button "OK" - if the data are valid against condition we do nothing and the DialogService close (normal behavior) ELSE (data not valid ) we display messagebox and the DialogService is still shown with last data entered.
-
But this did'nt solve my problem :) because what I need is : - let user enter some data (if no data => the button still disabled related to
CanCreateRole
- when there is data click on Button "OK" - if the data are valid against condition we do nothing and the DialogService close (normal behavior) ELSE (data not valid ) we display messagebox and the DialogService is still shown with last data entered.
So do your extra validation in the
CreateRole
method, and don't close the dialog if it fails. Or are you saying that the dialog always closes after invoking the command? If that's the case, we'll need to know what the implementation of your dialog service looks like.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
So do your extra validation in the
CreateRole
method, and don't close the dialog if it fails. Or are you saying that the dialog always closes after invoking the command? If that's the case, we'll need to know what the implementation of your dialog service looks like.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
the code of command is as described in the first question :
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};Yes, but we can't see your dialog service code. If it's something you've written, then you need to show the relevant parts of the code. If it's something you got from an article or GitHub project, then we'll need a link to the source.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Yes, but we can't see your dialog service code. If it's something you've written, then you need to show the relevant parts of the code. If it's something you got from an article or GitHub project, then we'll need a link to the source.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
In my MainWindow.xaml (which will validate data after click on OK )
in MainWindow.cs (the ViewModel related to the MainWindow.xaml)
\_roleViewModel = new Role\_ViewModel(eTypeOperation); var createCommand = new UICommand { Id = MessageBoxResult.OK, Caption = Properties.Resources.CstOk, IsCancel = false, IsDefault = true, Command = new DelegateCommand(CreateRole, CanCreateRole) }; var cancelCommand = new UICommand { Id = MessageBoxResult.Cancel, Caption = Properties.Resources.CstCancel, IsCancel = true, IsDefault = false, }; RoleService.ShowDialog(new List { createCommand, cancelCommand},Properties.Resources.CstNewRole, \_roleViewModel);
private void CreateRole()
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
}private bool CanCreateRole()
{
return !string.IsNullOrEmpty(_roleViewModel.RoleName.Trim());
} -
In my MainWindow.xaml (which will validate data after click on OK )
in MainWindow.cs (the ViewModel related to the MainWindow.xaml)
\_roleViewModel = new Role\_ViewModel(eTypeOperation); var createCommand = new UICommand { Id = MessageBoxResult.OK, Caption = Properties.Resources.CstOk, IsCancel = false, IsDefault = true, Command = new DelegateCommand(CreateRole, CanCreateRole) }; var cancelCommand = new UICommand { Id = MessageBoxResult.Cancel, Caption = Properties.Resources.CstCancel, IsCancel = true, IsDefault = false, }; RoleService.ShowDialog(new List { createCommand, cancelCommand},Properties.Resources.CstNewRole, \_roleViewModel);
private void CreateRole()
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
}private bool CanCreateRole()
{
return !string.IsNullOrEmpty(_roleViewModel.RoleName.Trim());
}So you're using the DevExpress MVVM framework? Looking at the documentation[^], your command can take a
CancelEventArgs
parameter to allow it to keep the dialog open:Online Documentation - Developer Express Inc.[^]:
Note that dialog commands take a CancelEventArgs object as a parameter. When dialog commands are invoked, the dialog is closed by default. To prevent this behavior, it is necessary to set the CancelEventArgs.Cancel parameter to True.
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand<CancelEventArgs>(CreateRole, CanCreateRole)
};private bool CanCreateRole(CancelEventArgs e)
{
// NB: IsNullOrWhiteSpace(value) is more efficient than IsNullOrEmpty(value.Trim()),
// and avoids a NullReferenceException if the string is null.
return !string.IsNullOrWhiteSpace(_roleViewModel.RoleName);
}private void CreateRole(CancelEventArgs e)
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
else
{
// Keep the dialog open:
e.Cancel = true;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
So you're using the DevExpress MVVM framework? Looking at the documentation[^], your command can take a
CancelEventArgs
parameter to allow it to keep the dialog open:Online Documentation - Developer Express Inc.[^]:
Note that dialog commands take a CancelEventArgs object as a parameter. When dialog commands are invoked, the dialog is closed by default. To prevent this behavior, it is necessary to set the CancelEventArgs.Cancel parameter to True.
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand<CancelEventArgs>(CreateRole, CanCreateRole)
};private bool CanCreateRole(CancelEventArgs e)
{
// NB: IsNullOrWhiteSpace(value) is more efficient than IsNullOrEmpty(value.Trim()),
// and avoids a NullReferenceException if the string is null.
return !string.IsNullOrWhiteSpace(_roleViewModel.RoleName);
}private void CreateRole(CancelEventArgs e)
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
else
{
// Keep the dialog open:
e.Cancel = true;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer