记录保存成功后显示信息
Show message after a successful record saving
我是 XAF Blazor 的新手,所以我试图在成功保存记录后向最终用户显示一条消息,所以我编写了以下代码:
public partial class MessageSavedSuccessfullyViewController : ViewController
{
public MessageSavedSuccessfullyViewController()
{
InitializeComponent();
}
protected override void OnActivated()
{
base.OnActivated();
View.ObjectSpace.Committing += ObjectSpace_Committing;
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
}
protected override void OnDeactivated()
{
View.ObjectSpace.Committing -= ObjectSpace_Committing;
base.OnDeactivated();
}
private void ObjectSpace_Committing(object sender, CancelEventArgs e)
{
if (View.ObjectSpace.IsCommitting)
{
MessageOptions options = new();
options.Duration = 2000;
options.Message = string.Format("Record Saved Successfully");
options.Type = InformationType.Success;
options.Web.Position = InformationPosition.Right;
options.Win.Caption = "Success";
options.Win.Type = WinMessageType.Toast;
Application.ShowViewStrategy.ShowMessage(options);
}
}
}
但是当我 运行 代码时,没有任何反应。
有什么我想念的吗?
此代码应在我的整个应用程序中使用,而不仅仅是在特定视图中使用。
public partial class MessageSavedSuccessfullyViewController : ViewController<DetailView>
{
private string message;
public MessageSavedSuccessfullyViewController()
{
InitializeComponent();
}
protected override void OnActivated()
{
base.OnActivated();
View.ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;
View.ObjectSpace.Committed += ObjectSpace_Committed;
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
}
protected override void OnDeactivated()
{
View.ObjectSpace.ObjectChanged -= ObjectSpace_ObjectChanged;
View.ObjectSpace.Committed -= ObjectSpace_Committed;
base.OnDeactivated();
}
void ObjectSpace_Committed(object sender, EventArgs e)
{
MessageOptions options = new();
options.Duration = 2000;
options.Message = message;
options.Type = InformationType.Success;
options.Web.Position = InformationPosition.Right;
options.Win.Caption = "Success";
options.Win.Type = WinMessageType.Toast;
Application.ShowViewStrategy.ShowMessage(options);
message = string.Empty;
}
void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
{
if (ObjectSpace.IsNewObject(e.Object))
{
message=string.Format("Record Saved Successfully");
}
else if (ObjectSpace.IsDeleting)
{
message = string.Format("Record Deleted Successfully");
}
else if (ObjectSpace.IsModified && e.OldValue != e.NewValue)
{
message = string.Format("Record Updated Successfully");
}
}
}
我是 XAF Blazor 的新手,所以我试图在成功保存记录后向最终用户显示一条消息,所以我编写了以下代码:
public partial class MessageSavedSuccessfullyViewController : ViewController
{
public MessageSavedSuccessfullyViewController()
{
InitializeComponent();
}
protected override void OnActivated()
{
base.OnActivated();
View.ObjectSpace.Committing += ObjectSpace_Committing;
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
}
protected override void OnDeactivated()
{
View.ObjectSpace.Committing -= ObjectSpace_Committing;
base.OnDeactivated();
}
private void ObjectSpace_Committing(object sender, CancelEventArgs e)
{
if (View.ObjectSpace.IsCommitting)
{
MessageOptions options = new();
options.Duration = 2000;
options.Message = string.Format("Record Saved Successfully");
options.Type = InformationType.Success;
options.Web.Position = InformationPosition.Right;
options.Win.Caption = "Success";
options.Win.Type = WinMessageType.Toast;
Application.ShowViewStrategy.ShowMessage(options);
}
}
}
但是当我 运行 代码时,没有任何反应。
有什么我想念的吗?
此代码应在我的整个应用程序中使用,而不仅仅是在特定视图中使用。
public partial class MessageSavedSuccessfullyViewController : ViewController<DetailView>
{
private string message;
public MessageSavedSuccessfullyViewController()
{
InitializeComponent();
}
protected override void OnActivated()
{
base.OnActivated();
View.ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;
View.ObjectSpace.Committed += ObjectSpace_Committed;
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
}
protected override void OnDeactivated()
{
View.ObjectSpace.ObjectChanged -= ObjectSpace_ObjectChanged;
View.ObjectSpace.Committed -= ObjectSpace_Committed;
base.OnDeactivated();
}
void ObjectSpace_Committed(object sender, EventArgs e)
{
MessageOptions options = new();
options.Duration = 2000;
options.Message = message;
options.Type = InformationType.Success;
options.Web.Position = InformationPosition.Right;
options.Win.Caption = "Success";
options.Win.Type = WinMessageType.Toast;
Application.ShowViewStrategy.ShowMessage(options);
message = string.Empty;
}
void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
{
if (ObjectSpace.IsNewObject(e.Object))
{
message=string.Format("Record Saved Successfully");
}
else if (ObjectSpace.IsDeleting)
{
message = string.Format("Record Deleted Successfully");
}
else if (ObjectSpace.IsModified && e.OldValue != e.NewValue)
{
message = string.Format("Record Updated Successfully");
}
}
}