|
167 | 167 | <local:ControlExample x:Name="Example6" HeaderText="A TabControl with closing handler"> |
168 | 168 | <ikw:SimpleStackPanel> |
169 | 169 | <TextBlock TextWrapping="Wrap" Margin="0,0,0,12"> |
170 | | - The <Bold>TabControl</Bold> now supports intercepting tab close requests via the |
171 | | - <Bold>TabItemCloseRequest</Bold> event. This allows preventing the close operation |
172 | | - dynamically - for example, to prompt the user for confirmation or prevent closing under certain conditions. |
173 | | - Simply handle the event and set <Bold>e.Cancel = true</Bold> to keep the tab open. |
| 170 | + The <Bold>TabControl</Bold> comes with a close button. To handle the close request, |
| 171 | + subscribe to the <Bold>TabCloseRequested</Bold> event. In the event handler, you should |
| 172 | + remove the tab from the TabControl's Items collection to close it if desired. |
| 173 | + Feel free to implement custom logic such as confirmation dialogs or saving states. |
| 174 | + <LineBreak/><LineBreak/> |
| 175 | + You can set <Bold>TabItem.(ui:TabItemHelper.IsClosable)</Bold> attached property to <Bold>False</Bold> to hide and disable |
| 176 | + the close button for specific tabs (or all tabs). |
174 | 177 | </TextBlock> |
175 | 178 |
|
176 | 179 | <TabControl x:Name="tabControl6" MinHeight="160" |
177 | 180 | ui:TabControlHelper.TabCloseRequested="tabControl6_TabCloseRequested"> |
178 | 181 | <TabItem x:Name="TabItem_Example6_Tab1" Header="Closable 1"> |
179 | 182 | <TextBlock TextWrapping="Wrap" Margin="12"> |
180 | | - This tab demonstrates the default close behavior. When the close button is clicked, the tab closes immediately |
181 | | - without any interception or confirmation. TabItemCloseRequest handler will not do anything for this tab. |
| 183 | + This tab can be closed normally by clicking the close button. When the close button is clicked, |
| 184 | + codebehind will handle the <Bold>TabCloseRequested</Bold> event and remove this tab from the TabControl's |
| 185 | + Items collection. |
182 | 186 | </TextBlock> |
183 | 187 | </TabItem> |
184 | 188 | <TabItem x:Name="TabItem_Example6_Tab2" Header="Closable 2"> |
185 | 189 | <TextBlock TextWrapping="Wrap" Margin="12"> |
186 | | - This tab demonstrates the default close behavior. When the close button is clicked, the tab closes immediately |
187 | | - without any interception or confirmation. TabItemCloseRequest handler will not do anything for this tab. |
| 190 | + This tab can be closed normally by clicking the close button. When the close button is clicked, |
| 191 | + codebehind will handle the <Bold>TabCloseRequested</Bold> event and remove this tab from the TabControl's |
| 192 | + Items collection. |
188 | 193 | </TextBlock> |
189 | 194 | </TabItem> |
190 | 195 | <TabItem x:Name="TabItem_Example6_Tab3" Header="Confirm To Close" Tag="ConfirmClose"> |
191 | 196 | <TextBlock TextWrapping="Wrap" Margin="12"> |
192 | | - This tab intercepts the close request using the <Bold>TabItemCloseRequest</Bold> event. |
193 | | - When the close button is clicked, a confirmation dialog appears. If the user chooses to cancel, |
194 | | - the tab remains open. This is useful for preserving unsaved work or preventing accidental closure. |
| 197 | + This tab requires confirmation before closing. When the close button is clicked, |
| 198 | + the <Bold>TabItemCloseRequest</Bold> event is handled in codebehind, prompting the user |
| 199 | + with a confirmation dialog. If the user confirms, the tab is closed; otherwise, the event |
| 200 | + handler will not do anything, leaving the tab open. |
195 | 201 | </TextBlock> |
196 | 202 | </TabItem> |
197 | 203 | <TabItem x:Name="TabItem_Example6_Tab4" Header="DON'T TOUCH ME!" Tag="NiceTry"> |
198 | 204 | <TextBlock TextWrapping="Wrap" Margin="12"> |
199 | | - This tab is configured to reject all close requests. The <Bold>TabItemCloseRequest</Bold> event is handled |
200 | | - and <Bold>e.Cancel</Bold> is always set to <Bold>true</Bold>, making the tab effectively non-closable. |
201 | | - <LineBreak/> |
202 | | - This is not usually recommended for user experience, but it demonstrates the flexibility of the event handling. |
| 205 | + This tab cannot be closed. When the close button is clicked, the <Bold>TabItemCloseRequest</Bold> |
| 206 | + handler doesn't do anything, preventing the tab from being closed. |
203 | 207 | </TextBlock> |
204 | 208 | </TabItem> |
205 | 209 | <TabItem x:Name="TabItem_Example6_Tab5" Header="Unclosable (nobutt) " |
206 | 210 | ui:TabItemHelper.IsClosable="False"> |
207 | 211 | <TextBlock TextWrapping="Wrap" Margin="12"> |
208 | | - This tab demonstrates the default close behavior. When the close button is clicked, the tab closes immediately |
209 | | - without any interception or confirmation. TabItemCloseRequest handler will not do anything for this tab. |
| 212 | + This tab cannot be closed because the close button is hidden and disabled by setting |
| 213 | + <Bold>ui:TabItemHelper.IsClosable</Bold> attached property to <Bold>False</Bold>, |
| 214 | + thus, the close button is not shown. |
210 | 215 | </TextBlock> |
211 | 216 | </TabItem> |
212 | 217 |
|
|
0 commit comments