简体   繁体   English

在WPF中显示状态消息的最佳方法是什么?

[英]What is the best way to display a status message in WPF?

I have several wpf pages with update/delete/add buttons. 我有几个带有更新/删除/添加按钮的WPF页面。 I want to display to the user messages like "successful delete", etc. How can I best implement this so the message is defined in a single place (similar to an asp.net master page) and I can update this message from anywhere? 我想向用户显示“成功删除”之类的消息。如何最好地实现此消息,以便在单个位置(类似于asp.net主页)中定义消息,并且可以从任何地方更新此消息?

You may want to consider doing a publish/subscribe ("Observer" pattern) -- define a "status changed" event on a base page, and create a custom control that sets up a delegate and event handler to listen for status updates. 您可能需要考虑进行发布/订阅(“观察者”模式)-在基础页面上定义“状态更改”事件,并创建一个自定义控件,该控件设置委托和事件处理程序以侦听状态更新。

Then you could drop the custom control on any page that inherits from the base, and it would automatically listen for and display status messages whenever the event is fired. 然后,您可以将自定义控件放在从基础继承的任何页面上,并且一旦触发该事件,它将自动侦听并显示状态消息。

Edit: I put together a sample implementation of this pattern and published a blog post walking through the code. 编辑:我整理了此模式的示例实现,并发布了一篇博文,逐步介绍了该代码。

I don't think you have the ASP.Net master pages translated to the WPF Page world just yet. 我认为您还没有将ASP.Net母版页转换为WPF页面世界。
A workaround till MS gets there, I would probably put a Control at the top of the page (or wherever) that just displays a particular User-level " Application Setting ". 直到MS到达那里的一种解决方法,我可能会在页面顶部(或任何位置)放置一个仅显示特定用户级“ 应用程序设置 ”的控件。 You can update the string property like 您可以像这样更新字符串属性

MyAppUserSettings.StatusMessage = "You just deleted the administrator!" 

Crude but will get the job done I think! 粗略,但我认为可以完成工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM