开发者

Custom Message Box in WPF - What project type?

开发者 https://www.devze.com 2022-12-23 06:52 出处:网络
I have a WPF Composite application and I want to create a customized messagebox, I wondered what project type I should use to create it?

I have a WPF Composite application and I want to create a customized messagebox, I wondered what project type I should use to create it?

  1. 开发者_StackOverflowA usercontrol
  2. A WPF Application
  3. A Class Library

I have to then be able to use this MessageBox in other places in my application.


I have to then be able to use this MessageBox in other places in my application.

Since you want to share and reuse the component, you should probably not use an application project; it is technically possible to reference an application project from another project, but it's not very idiomatic. So you want a library project instead. In Visual Studio, the Class Library, WPF Custom Control Library and WPF User Control project types are all library projects: the only difference is which system DLL references are set up for you, the initial files generated, and what VS puts on the Add Item menu.

So any of these three options will be fine, but my recommendation would be either WPF User Control Library or WPF Custom Control Library since that will:

  1. automatically include references to the WPF DLLs; and
  2. set up the Add Item menu to make it easier for you to add actual controls to the library in future (since you are bound to come up with some reusable controls as well as your message box, and you may as well stick them in the same project).


I have implemented a WPF MessageBox fully customizable via standard WPF control templates:

http://blogs.microsoft.co.il/blogs/arik/archive/2011/05/26/a-customizable-wpf-messagebox.aspx

Features

  • The class WPFMessageBox has the exact same interface as the current WPF MessageBox class.
  • Implemented as a custom control, thus fully customizable via standard WPF control templates.
  • Has a default control template which looks like the standard MessageBox.
  • Supports all the common types of message boxes: Error, Warning, Question and Information.
  • Has the same “Beep” sounds as when opening a standard MessageBox.
  • Supports the same behavior when pressing the Escape button as the standard MessageBox.
  • Provides the same system menu as the standard MessageBox, including disabling the Close button when the message box is in Yes-No mode.
  • Handles right-aligned and right-to-left operating systems, same as the standard MessageBox.
  • Provides support for setting the owner window as a WinForms Form control.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号