Skip to content

Commit cee0ccb

Browse files
docs(window): clarifications on capturing the user close action
1 parent 95a95f4 commit cee0ccb

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

components/window/events.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can use the `VisibleChanged` event to get notifications when the user tries
2929
````CSHTML
3030
@result
3131
32-
<button @onclick="ToggleWindow">Toggle the Window</button>
32+
<TelerikButton OnClick="@ToggleWindow">Toggle the Window</TelerikButton>
3333
3434
<TelerikWindow Visible="@isVisible" VisibleChanged="@VisibleChangedHandler">
3535
<WindowTitle>
@@ -52,6 +52,8 @@ You can use the `VisibleChanged` event to get notifications when the user tries
5252
isVisible = currVisible; // if you don't do this, the window won't close because of the user action
5353
5454
result = $"the window is now visible: {isVisible}";
55+
56+
Console.WriteLine("The user closed the window with the [x] button on its toolbar");
5557
}
5658
5759
public void ToggleWindow()
@@ -63,6 +65,50 @@ You can use the `VisibleChanged` event to get notifications when the user tries
6365
}
6466
````
6567

68+
>caption Prevent the user from closing the window based on a condition
69+
70+
````CSHTML
71+
@* Not propagating the visible value from the handler to the model can prevent the user from closing the window
72+
Using the application code to explicitly set the visibility of the window will still close it as it will not fire the event*@
73+
74+
<TelerikButton OnClick="@( _ => isVisible = !isVisible )">Toggle the Window</TelerikButton>
75+
76+
<TelerikWindow Visible="@isVisible" VisibleChanged="@VisibleChangedHandler">
77+
<WindowTitle>
78+
<strong>The Title</strong>
79+
</WindowTitle>
80+
<WindowContent>
81+
Try closing the window with the [x] button on its toolbar, then toggle the checkbox and try again.
82+
<br />
83+
<label>
84+
The user can close the window with the [x] button:
85+
<TelerikCheckBox @bind-Value="@isClosable" />
86+
</label>
87+
</WindowContent>
88+
<WindowActions>
89+
<WindowAction Name="Close" />
90+
</WindowActions>
91+
</TelerikWindow>
92+
93+
@code {
94+
bool isVisible { get; set; } = true;
95+
bool isClosable { get; set; }
96+
97+
void VisibleChangedHandler(bool currVisible)
98+
{
99+
if (isClosable)
100+
{
101+
isVisible = currVisible; // if you don't do this, the window won't close because of the user action
102+
}
103+
else
104+
{
105+
Console.WriteLine("The user tried to close the window but the code didn't let them");
106+
}
107+
108+
}
109+
}
110+
````
111+
66112
## StateChanged
67113

68114
You can use the `StateChanged` event to get notifications when the user tries to minimize, maximize or restore the window. You can effectively cancel the event by *not* propagating the new state to the variable the `State` property is bound to.

0 commit comments

Comments
 (0)