Pilz.UI aktualisieren
105
Pilz.UI.md
105
Pilz.UI.md
@@ -1 +1,104 @@
|
|||||||
tba
|
[[_TOC_]]
|
||||||
|
|
||||||
|
# Dialogs
|
||||||
|
|
||||||
|
## Create an UI
|
||||||
|
|
||||||
|
Create a new `UserControl` via the template in Visual Studio. Then change the inherited class `UserControl` to `FlyoutBase`.
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
| Name | Type | Note |
|
||||||
|
|------|------|------|
|
||||||
|
| `ActionPanelVisible` | `bool` | If `true` the default action panel will be visible.`true` by default. |
|
||||||
|
| `CancelButtonVisible` | `bool` | If `true` the cancel button will be visible.`true` by default. |
|
||||||
|
| `CancelButtonEnabled` | `bool` | If `true` the cancel button will be enabled. `true` by default. |
|
||||||
|
| `ConfirmButtonVisible` | `bool` | If `true` the confirm button will be visible. `true` by default. |
|
||||||
|
| `Title` | `string` | Set this to something other then `null` or `""` to show the title bar and set it's title. The title will not be shown otherwise. |
|
||||||
|
| `TitleIcon` | `Image` | Set this to something other then `null` to show the title bar and set it's icon. The icon will not be show otherwise. |
|
||||||
|
| `RegisterDialogAccept` | `bool` | If `true` the cancel button will be registred as `AcceptButton` at the form it will be added to. `true` by default. |
|
||||||
|
| `RegisterDialogCancel` | `bool` | If `true` the cancel button will be registred as `CancelButton` at the form it will be added to. `false` by default. |
|
||||||
|
|
||||||
|
### Validation
|
||||||
|
|
||||||
|
The default action bar and its OK button calls a method to validate if it can be ok. It will only return ok if `ValidateOK` returns `true`. The `base` just always returns `true`, but you can overwrite this method and add your own checks.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
protected override bool ValidateOK()
|
||||||
|
{
|
||||||
|
// Validate inputs
|
||||||
|
if (string.IsNullOrWhitespace(textBox_Name.Text)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Save inputs
|
||||||
|
myResult.Name = textBox_Name.Text.Trim();
|
||||||
|
|
||||||
|
// Return success
|
||||||
|
return base.ValidateOK;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Close
|
||||||
|
|
||||||
|
If you won't want to use the default action bar, you may want to close the flyout/dialog yourself. There is a method you can use for. Set the `DialogResult` to indicate why the flyout/dialog should be closed.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
private void Button_Cancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Close(DialogResult.Cancel);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Use the UI as flyout
|
||||||
|
|
||||||
|
_This feature has not been finished yet!_
|
||||||
|
|
||||||
|
## Use the UI as dialog
|
||||||
|
|
||||||
|
Use the static `DialogBase.Show<>()` or `DialogBase.Show()` methods to open a dialog. This will use the provided istance or create a new one of the provided type.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var flyout = DialogBase.Show<MyFlyout>(listView_Accounts, strTitle, svgSymbol);
|
||||||
|
if (flyout.Result == DialogResult.OK)
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Events for prepair & result callback
|
||||||
|
|
||||||
|
There are some static events you can use to initialize a flyout or get back the some values.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public AccountManagerPage()
|
||||||
|
{
|
||||||
|
DialogBase.DialogLoading += DialogBase_DialogLoading;
|
||||||
|
DialogBase.DialogClosed += DialogBase_DialogClosed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DialogBase_DialogLoading(DialogLoadingEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Parent == this && e.Content is MyFlyout flyout)
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DialogBase_DialogClosed(DialogClosedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Parent == this && e.Content is MyFlyout flyout && flyout.Result == DialogResult.OK)
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Ensure you unregister your handlers from the event on Dispose or deconstructor!
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
~AccountManagerPage()
|
||||||
|
{
|
||||||
|
DialogBase.DialogLoading -= DialogBase_DialogLoading;
|
||||||
|
DialogBase.DialogClosed -= DialogBase_DialogClosed;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user