Custom Message Box in WPF - What project type?
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?
- 开发者_StackOverflowA usercontrol
- A WPF Application
- 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:
- automatically include references to the WPF DLLs; and
- 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.
精彩评论