This is a migrated thread and some comments may be shown as answers.

Can't show window form different component

1 Answer 320 Views
Window
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Iron
Veteran
Robert asked on 22 Oct 2020, 12:40 PM

Window-component:

<TelerikWindow @bind-Visible="@_visible">
    <WindowTitle>Window</WindowTitle>
</TelerikWindow>
<TelerikButton OnClick="Show">Toggle</TelerikButton>

@code
{
    private bool _visible;

    public void Show()
    {
        _visible = !_visible;
    }
}

Other component:

<WindowComponent @ref="_windowComp"/>
<TelerikButton OnClick="() => _windowComp.Show()">Show</TelerikButton>

@code {
    private WindowComponent  _windowComp;
}

Nothing happens when pressing the "Show"-button, although debugging clearly shows that the Show()-method is executed.

 

1 Answer, 1 is accepted

Sort by
0
Svetoslav Dimitrov
Telerik team
answered on 23 Oct 2020, 08:17 AM

Hello Robert,

You should call a StateHasChanged() at the end of the show method (like the example I added below). The reason is that Blazor does not know what that method does and if it should render the HTML anew.

Code snippet:

    public void Show()
    {
        _visible = !_visible;

        StateHasChanged();
    }

Regards,
Svetoslav Dimitrov
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
Robert
Top achievements
Rank 1
Iron
Veteran
Answers by
Svetoslav Dimitrov
Telerik team
Share this question
or