The UserControl
, the User
Tip
See the MessageBox topic for additional details on showing basic user prompts.
Basic Usage
The basic flow for User
- Create a new User
Prompt .Builder - Use
With*
methods to configure properties to be applied to the UserPrompt when it is built.Control - Show the prompt.
User
Create Builder
To get started, call User
Configure Properties
The UserWith<PropertyName>
where <PropertyName>
is the name of the User
Use method-chaining to apply all desired configuration options.
Important
Each configured property on Usernullable
, and each With*
method accepts a null
reference. Only properties configured with non-null
values will be configured on UserWith*
method and passing null
will effectively clear the configuration for that property.
Global Configuration
There are two methods available to register callbacks that are always invoked to configure each new instance of User
All User Prompts
The User
The following example demonstrates how a global callback can be registered to use the theme-solid accent
style classes on the default button (if any) for every prompt:
MessageBox Only
The Message
The following example demonstrates how a global callback can be registered that alters the default behavior by displaying a message box title in the header of the prompt:
Show Prompt
Finally, call the Show method. This will create the User
Example
The following code sample demonstrates how User
The fluent API allows the entire configuration to be defined as a single statement.
Warning
The return value of UserTask<MessageBoxResult>
that must be awaited to prevent the calling thread from proceeding before the user responds.
See the User Prompt Content and User Prompt Buttons topics for more details and examples.
Builder Lifecycle and Callbacks
Nothing happens with User
- Create a User
Prompt and assign to the Instance property.Control - Invoke all After
Initialize callbacks. - Assign properties on User
Prompt . After this point, the Instance property is fully initialized any changes to builder properties that affect the configuration of the UserControl Prompt will not be applied.Control - Invoke all After
Build callbacks. - Use the Requested
Display to determine how the prompt will be displayed and assign the ActualMode Display property to the mode that is used.Mode - Invoke all Before
Show callbacks. - When displayed as a Dialog...
- Configure User
Prompt to host the UserWindow Prompt .Control - Invoke all After
Initialize callbacks.Window - Show the User
Prompt as a dialog and await a response.Window
- Configure User
- When displayed as an Overlay...
- Configure an overlay to host the User
Prompt .Control - Show the overlay and await a response.
- Configure an overlay to host the User
- Invoke all On
Responding callbacks when a response is indicated. - Invoke all After
Show callbacks with the indicated result. - Return the result.
Callbacks are available at different stages of the build process to support extensibility.
Note
Adding a callback does not replace any already registered callbacks. Any newly registered callback will be invoked after previously registered callbacks are invoked.
Instance Property
The Usernull
until the Show method is called. All callbacks can safely read this property to interact with the User
Tip
To interact with the User
Tag Property
The User
AfterInitialize Callback
This callback is invoked immediately after an instance of User
AfterBuild Callback
This callback is invoked after all builder configuration settings have been applied and can be used to finalize the User
Important
At this stage in the lifecycle, the User
BeforeShow Callback
This callback is invoked before attempting to show the prompt. At this point, the Requested
AfterInitializeWindow Callback (Dialogs Only)
When displayed as a Dialog, this callback is invoked to finalize the User
OnResponding Callback
This callback is invoked when the user indicates a response and can be used to confirm and/or cancel the response using the User
AfterShow Callback
This callback is invoked after the prompt is closed and passes the Message