visiblechanged event not firing on window close

1 Answer 166 Views
Window
Lawrence
Top achievements
Rank 1
Lawrence asked on 12 May 2021, 06:16 PM

The VisibleChangedHandler is never hit, either on open or close.  Using version 2.23.0

 

My code/markup is as such:

 <TelerikWindow Visible="@documentWindowVisible" VisibleChanged="@VisibleChangedHandler">
        <WindowTitle>View/Manage Attachment</WindowTitle>
        <WindowContent>
            <div id="tooltipmanagedocument" title="View Current Document"></div>
            <TelerikEditor @bind-Value="@currentAttachment.Content"></TelerikEditor>
            <TelerikButton OnClick="@UpsertDocument" Icon="save"></TelerikButton>
            <TelerikButton OnClick="@ExportToPDF" Icon="download"></TelerikButton>
            <label>
                Upload Attachment (will overwrite existing Attachment but retain history)
                <InputFile OnChange="@LoadDocumentFromDisk" accept=".docx"/>
            </label>
        </WindowContent>
        <WindowActions>
            <WindowAction Name="Maximize"></WindowAction>
            <WindowAction OnClick="hideManageDocument" Name="Close"></WindowAction>
        </WindowActions>

    </TelerikWindow>

 

public void VisibleChangedHandler(bool currVisible)
        {
            if (currVisible)
            {
                documentWindowVisible = true;
                if (IsThereACurrentAttachment)
                {
                    LoadDocumentFromDB();
                }
                else
                {
                    // need to make load document button invisible
                }
            } 
            else
            {
                documentWindowVisible = false;
            }
        }

 

Lawrence
Top achievements
Rank 1
commented on 12 May 2021, 06:29 PM

I may have found it but it doesn't explain everything. I am also using "WindowAction" for the close event and that OnClick event is firing ok and perhaps taking the visibility change event? However, even if that is happening it doesn't explain why the visibility change event doesn't fire when it becomes visible.

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 12 May 2021, 06:38 PM

Hello Lawrence,

The VisibleChanged event fires only when the user closes the window from the built-in close command. Changing the Visible field in the view-model will hide that window without raising the event - changing values in the view-model never raises events because that can cause an endless loop. If you are changing the value with your own code, you can call the next code you want to run with your own code as needed, instead of relying on component events.

So, the following seems to work fine for me, and I am attaching a short video of the expected behavior as a reference so you can confirm if I am missing something:

@result

<TelerikButton OnClick="@ToggleWindow">Toggle the Window</TelerikButton>

<TelerikWindow Visible="@isVisible" VisibleChanged="@VisibleChangedHandler">
    <WindowTitle>
        <strong>The Title</strong>
    </WindowTitle>
    <WindowContent>
        This is my window <strong>popup</strong> content.
    </WindowContent>
    <WindowActions>
        <WindowAction Name="Close" />
    </WindowActions>
</TelerikWindow>

@code {
    bool isVisible { get; set; }
    string result { get; set; }

    void VisibleChangedHandler(bool currVisible) // this will always come in as false
    {
        isVisible = currVisible; // if you don't do this, the window won't close because of the user action

        result = $"the window is now visible: {isVisible}";

        Console.WriteLine("The user closed the window with the [x] button on its toolbar");
    }

    public void ToggleWindow()
    {
        isVisible = !isVisible;

        result = $"the window is now visible: {isVisible}";
    }
}

If this does not help you move forward, please edit your post to show a fully runnable version of my snippet that does not fire the event when expected so I can have a look.

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Window
Asked by
Lawrence
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or