Application Data Component

Description

This component handles the rendering of various forms within the application using Blazor. It listens for changes in the application state and updates the UI accordingly.

Usage

@using Gap.Blazor
@using Gap.Blazor.Components
@using Microsoft.AspNetCore.Components.Rendering
@using System.Reflection
@namespace Gap.Blazor.Components

@code {
    private bool HasChanged = false;

    protected override void OnInitialized()
    {
        base.OnInitialized();
    }

    protected override void OnAfterRender(bool firstRender)
    {
        base.OnAfterRender(firstRender);
        if (firstRender)
        {
            Application.CurrentApplication.ItemHasChanged += CurrentApplication_ItemHasChanged;
        }
        this.HasChanged = false;
    }

    /// <summary>
    /// Handles the ItemHasChanged event of the CurrentApplication control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
    private void CurrentApplication_ItemHasChanged(object sender, EventArgs e)
    {
        if (!HasChanged)
        {
            HasChanged = true;
            this.InvokeAsync(() => this.StateHasChanged());
        }
    }
}

<div>
    @foreach (Gap.Blazor.Form form in Application.ActiveForms)
    {
        if (!form.IsMdiChild){
            if (form.View != null)
            {
                var formArgs = new Dictionary<string, object>();
                formArgs.Add("model", form);
                <DynamicComponent @key="form" Type="@form.View" Parameters="@formArgs"></DynamicComponent>
            }
            else if (form is MessageBox msgBox)
            {
                <WMMessageBoxComponent @key="msgBox" model="msgBox"></WMMessageBoxComponent>
            }
            else if (form is InputBox inputBoxForm)
            {
                <WMInputBoxFormComponent @key="inputBoxForm" model="inputBoxForm"></WMInputBoxFormComponent>
            }
            else
            {
                <WMFormComponent @key="form" model="@form"></WMFormComponent>
            }
        }
    }
</div>

Properties

  • HasChanged: Boolean flag indicating if the application state has changed.

Methods

  • OnInitialized(): Initializes the component.

  • OnAfterRender(bool firstRender): Executes after the component has rendered. Subscribes to the ItemHasChanged event if it's the first render.

  • CurrentApplication_ItemHasChanged(object sender, EventArgs e): Handles the ItemHasChanged event of the CurrentApplication control.

Events

  • ItemHasChanged: Event triggered when an item in the application changes.

Dynamic Rendering

The component dynamically renders different types of forms based on their type:

  • DynamicComponent: Renders the form's view if it exists.

  • WMMessageBoxComponent: Renders a message box form.

  • WMInputBoxFormComponent: Renders an input box form.

  • WMFormComponent: Renders a general form.

Last updated