7
Pilz.UI.Telerik
Pilzinsel64 edited this page 2024-07-08 05:24:59 +00:00

[[TOC]]

Dialogs

Create an UI

Create a new UserControl via the template in Visual Studio. Then change the inherited class UserControl to RadFlyoutBase.

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 RadSvgImage 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.

protected override bool ValidateOK()
{
    // Validate inputs
    if (string.IsNullOrWhitespace(radTextBox_Name.Text)
        return false;

    // Save inputs
    myResult.Name = radTextBox_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.

private void RadButton_Cancel_Click(object sender, EventArgs e)
{
    Close(DialogResult.Cancel);
}

Use the UI as flyout

Use the static RadFlyoutBase.Show<>() method for opening a flyout. This uses RadFlyout as base and will create a new instance of the provided type.

RadFlyoutBase.Show<MyFlyout>(radListView_Accounts , strTitle, svgSymbol);

Events for prepair & result callback

There are some static events you can use to initialize a flyout or get back the some values.

public AccountManagerPage()
{
    RadFlyoutBase.FlyoutCreated += RadFlyoutBase_FlyoutCreated;
    RadFlyoutBase.FlyoutClosed += RadFlyoutBase_FlyoutClosed;
}

private void RadFlyoutBase_FlyoutCreated(FlyoutCreatedEventArgs e)
{
    if (RadFlyoutBase.ParentContext == radListView_Accounts && e.Content is MyFlyout flyout && flyout.Result == DialogResult.OK)
    {
        // ...
    }
}

private void RadFlyoutBase_FlyoutClosed(FlyoutClosedEventArgs e)
{
    if (RadFlyoutBase.ParentContext == radListView_Accounts && e.Content is MyFlyout flyout && flyout.Result == DialogResult.OK)
    {
        // ...
    }
}

Ensure you unregister your handlers from the event on Dispose or deconstructor!

~AccountManagerPage()
{
    RadFlyoutBase.FlyoutCreated += RadFlyoutBase_FlyoutCreated;
    RadFlyoutBase.FlyoutClosed += RadFlyoutBase_FlyoutClosed;
}

Use the UI as dialog

Use the static RadDialogBase.Show<>() or RadDialogBase.Show() methods to open a dialog. This will use the provided istance or create a new one of the provided type.

var flyout = RadDialogBase.Show<MyFlyout>(this, 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.

public AccountManagerPage()
{
    RadDialogBase.DialogLoading += RadDialogBase_DialogLoading;
    RadDialogBase.DialogClosed += RadDialogBase_DialogClosed;
}

private void RadDialogBase_DialogLoading(DialogLoadingEventArgs e)
{
   if (e.Parent == this && e.Content is MyFlyout flyout)
   {
       // ...
   }
}

private void RadDialogBase_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!

~AccountManagerPage()
{
    RadDialogBase.DialogLoading -= RadDialogBase_DialogLoading;
    RadDialogBase.DialogClosed -= RadDialogBase_DialogClosed;
}

Symbols

Setup SymbolFactory

Create a new directory, we call it Symbols here.

image{width=188 height=275}

Ensure you add this to the project file. This will mark all SVG files within the Symbols folder as embedded resource.

<ItemGroup>
  <EmbeddedResource Include="Symbols\*.svg" />
</ItemGroup>

Create a new enum. It may look like the following. Ensure you only add new values to the buttom as you will introduce a breaking change to your API otherwise.

public enum GlobalSymbols
{
    add,
    administrative_tools,
    billboard,
    cancel,
    delete,
    edit,
    home,
    login,
    logout,
    product,
    project,
    remove,
    save,
    settings,
}

The class GlobalsymbolFactory need to inherit from RadSymbolFactory<>. Provide your symbols enum here. You will need to overwrite GetImageResourceAssembly and GetImageRessourcePath as this parts can't be done by the base class.

public class GlobalSymbolFactory : RadSymbolFactory<GlobalSymbols>
{
    private static readonly string? symbolsNamespace = typeof(GlobalSymbolFactory).Namespace + ".Symbols";
    private static readonly string symbolsPathTemplate = "{0}.{1}.svg";

    public override Assembly GetImageResourceAssembly()
    {
        return Assembly.GetExecutingAssembly();
    }

    public override string GetImageRessourcePath(GlobalSymbols svgImage)
    {
        return string.Format(symbolsPathTemplate, symbolsNamespace, svgImage);
    }
}

Access symbols

Accessing symbols esaily via an instance of your SymbolFactory implementation. You can either provide a static instance in GlobalSymbolFactory or create a new instance wherever you need it. Access via GetSvgImage or GetImage, decide whenever you can use an RadSvgImage or need an Image.

// Static instance in GlobalSymbolFactory
public static IRadSymbolFactory<GlobalSymbols> Instance { get; } = new GlobalSymbolFactory();
var img = GlobalSymbolFactory.Instance.GetSvgImage(GlobalSymbols.billboard, SymbolSize.x16);

// Instance on-demand
var symbols = new GlobalSymbolFactory();
var img = symbols.GetSvgImage(GlobalSymbols.billboard, SymbolSize.x16);