Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PopupDragCompletedEventArgs.Start Property

Returns the Popup’s position before a drag-and-drop operation.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public Point Start { get; }

#Property Value

Type Description
Point

The initial coordinates.

#Remarks

The following code snippet handles DragStarted and DragCompleted events to save and load the current window position.

Razor
<div class="target-container" @onclick="@(() => PopupVisible = true)">
    <p class="target-caption">CLICK TO SHOW A POP-UP WINDOW</p>
</div>
<DxPopup AllowDrag="true"
         HeaderText="Popup"
         @bind-Visible="@PopupVisible"
         BodyText="@Constants.Text"
         PositionX="positionX"
         PositionY="positionY"
         DragCompleted="OnPopupDragCompleted">
</DxPopup>

@code {
    bool PopupVisible { get; set; } = false;
    const string LocalStorageKey = "DialogsAndWindows-Popup-Dragging";
    int? positionX, positionY;

    protected override async Task OnAfterRenderAsync(bool firstRender) {
        if (firstRender) {
            var position = await LoadPositionFromLocalStorageAsync();
            (positionX, positionY) = (position?.X ?? null, position?.Y ?? null);
            StateHasChanged();
        }
    }
    async Task OnPopupDragCompleted(PopupDragCompletedEventArgs args) {
        (positionX, positionY) = (args.End.X, args.End.Y);
        await SavePositionToLocalStorageAsync(args.End);
    }
    async Task<Point?> LoadPositionFromLocalStorageAsync() {
        var json = await JSRuntime.InvokeAsync<string>("localStorage.getItem", LocalStorageKey);
        return string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize<Point>(json);
    }
    async Task SavePositionToLocalStorageAsync(Point position) {
        await JSRuntime.InvokeVoidAsync("localStorage.setItem", LocalStorageKey, JsonSerializer.Serialize(position));
    }
}
See Also