Customizing Appearance
Several properties are available to customize the appearance of the control. The following additional customizations are also available:
Header
The HeaderBackground, HeaderForeground, HeaderFontSize, HeaderBorderBrush, HeaderBorderThickness properties are available to customize the header.
When either the HeaderBackground or HeaderBorderBrush properties are populated, the layout of the Header and Status Image will automatically shift their vertical alignment for a consistent layout.
UserPromptBuilder defines equivalent methods to set these properties with the builder pattern (e.g., WithHeaderBackground and WithHeaderForeground). For any IBrush
-based property, one method overload will accept an IBrush
and the other will accept a Color
that will automatically be converted to a SolidColorBrush
.
Images
Any object
can be set to the StatusIcon or FooterIcon properties for a custom look. When using the builder pattern, set the object
using WithStatusIcon or WithFooterIcon.
Since icon properties are defined as object
value types, a corresponding IDataTemplate
is typically required to define how the value should be presented. The StatusIconTemplate and FooterIconTemplate properties can be used to define an appropriate IDataTemplate
. If a IDataTemplate
is not explicitly defined, the IconPresenter.DefaultContentTemplate will be used, which is pre-configured to handle common value types like IImage
. See the Icon Presenter topic for details on how to customize the data templates or add support for additional data types.
The icons used by MessageBoxImage can also be customized by assigning a custom ImageProvider to the ImageProvider.Default property. Each value for MessageBoxImage corresponds to a key of the same name defined by SharedImageSourceKeys. For example, the image MessageBoxImage.Warning corresponds to the key SharedImageSourceKeys.Warning. A custom class which derives from ImageProvider can override the ImageProvider.GetImageSource method to return a custom IImage
for one or more of those keys.
Customize UserPromptWindow
The UserPromptWindow does not have a public constructor and is only created by the UserPromptWindow.ShowDialog method. One of the arguments for ShowDialog allows you to pass an Action<UserPromptWindow>
which is invoked with a reference to the UserPromptWindow after it is configured, but before it is shown. This callback allows the UserPromptWindow to be customized.
The following code demonstrates using the callback to customize the flow direction of the window:
var userPromptControl = new UserPromptControl() { ... };
Window owner = null; // Use default
await UserPromptWindow.ShowDialog(
userPromptControl,
"Window Title",
owner,
window => {
window.FlowDirection = FlowDirection.RightToLeft;
});
The builder pattern exposes the same customization using the AfterInitializeWindow callback as shown in the following example:
await UserPromptBuilder.Configure()
// ... other configuration options here
.AfterInitializeWindow(window => {
window.FlowDirection = FlowDirection.RightToLeft;
})
.Show();
Finally, an advanced configuration of MessageBox also allows access to the builder pattern as shown below:
await MessageBox.Show(
"Use the optional 'configure' parameter to access the UserPromptBuilder."
configure: builder => builder
.AfterInitializeWindow(window => {
window.FlowDirection = FlowDirection.RightToLeft;
})
);