|
1 | 1 | <!-- default badges list --> |
2 | | - |
3 | 2 | [](https://supportcenter.devexpress.com/ticket/details/T1288385) |
4 | 3 | [](https://docs.devexpress.com/GeneralInformation/403183) |
5 | 4 | [](#does-this-example-address-your-development-requirementsobjectives) |
6 | 5 | <!-- default badges end --> |
7 | | -# Product/Platform - Task |
| 6 | +# Blazor Tabs - Create a Dynamic Tabbed Interface |
8 | 7 |
|
9 | | -This is the repository template for creating new examples. Describe the solved task here. |
| 8 | +The example demonstrates how to create an interactive multi-tab web interface with DevExpress Blazor [Tabs](https://docs.devexpress.com/Blazor/405074/components/layout/tabs) and [Context Menu](https://docs.devexpress.com/Blazor/405060/components/navigation-controls/context-menu) components. |
10 | 9 |
|
11 | | -Put a screenshot that illustrates the result here. |
| 10 | + |
12 | 11 |
|
13 | | -Then, add implementation details (steps, code snippets, and other technical information in a free form), or add a link to an existing document with implementation details. |
| 12 | +It showcases core features that help end users build their personalized workspaces and multitask effectively. |
| 13 | + |
| 14 | +### Organize Content Into Tabs |
| 15 | + |
| 16 | +Place [DxTabs](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTabs) container on the page (_Components/Pages/Index.razor_) and add a [DxTabPage](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTabPage) for each tab. |
| 17 | + |
| 18 | +Insert your custom Blazor components or content directly into each DxTabPage. |
| 19 | + |
| 20 | +```razor |
| 21 | +<DxTabs @ref=tabs |
| 22 | + @bind-ActiveTabIndex=activeTabIndex |
| 23 | + AllowTabReorder="true" |
| 24 | + TabReordering="OnTabReordering" |
| 25 | + TabClosing="OnTabClosing" |
| 26 | + RenderMode="TabsRenderMode.AllTabs"> |
| 27 | + <DxTabPage CssClass="counter-tab" |
| 28 | + AllowClose="true" |
| 29 | + VisibleIndex="@collection.GetVisibleIndexByTabText("Counter")" |
| 30 | + Visible="@collection.GetVisibleByTabText("Counter")" |
| 31 | + Text="Counter"> |
| 32 | + <div class="tab-body"> |
| 33 | + <Counter /> |
| 34 | + </div> |
| 35 | + </DxTabPage> |
| 36 | +``` |
| 37 | + |
| 38 | +The CssClass property of a tab page serves as a unique identifier, allowing client-side scripts to interact with specific tabs. |
| 39 | + |
| 40 | +### Persist Tab State |
| 41 | + |
| 42 | +Implement a custom **MDITab** class to encapsulate specific properties of each individual tab. **MDITabCollection** will control visibility, display order, and titles of all tabs. The title links an underlying object to the visual tab representation in the UI. |
| 43 | + |
| 44 | +Bind these properties to the visual tab elements in the UI. To ensure the MDITabCollection accurately reflects the live interface, implement event handlers for TabReorder and TabClosing. These handlers will listen for user actions and dynamically update the collection to match the current tab state. |
| 45 | + |
| 46 | +To maintain the tab layout across sessions, serialize the collection to JSON and save it to the browser's local storage with **MDIStateHelper** class every time the UI layout changes. It maintains the tab visibility and order even after the user closes and reopens the browser. Tab state is restored in the OnAfterRenderAsync event handler. |
| 47 | + |
| 48 | +### Add Context Menu to Tabs |
| 49 | + |
| 50 | +Create a context menu that allows users to manage tabs: |
| 51 | + |
| 52 | +- Close the current tab. |
| 53 | +- Close all tabs. |
| 54 | +- Close all tabs except for the current one. |
| 55 | +- Restore closed tabs. |
| 56 | + |
| 57 | +Place [DxContextMenu](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxContextMenu) on the page (_Components/Pages/Index.razor_) and add a [DxContextMenuItem](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxContextMenuItem) for each menu action. |
| 58 | + |
| 59 | +```razor |
| 60 | +<DxContextMenu @ref=menu> |
| 61 | + <Items> |
| 62 | + <DxContextMenuItem Click="CloseTab" Text="Close"></DxContextMenuItem> |
| 63 | + <DxContextMenuItem Click="CloseAllTabs" Text="Close All Tabs"></DxContextMenuItem> |
| 64 | + <DxContextMenuItem Click="CloseOtherTabs" Text="Close Other Tabs"></DxContextMenuItem> |
| 65 | + <DxContextMenuItem Click="RestoreAllTabs" Text="Restore Closed Tabs"></DxContextMenuItem> |
| 66 | + </Items> |
| 67 | +</DxContextMenu> |
| 68 | +``` |
| 69 | + |
| 70 | +Implement a client-side script (_wwwroot/js/mdi.js_) to handle right-clicks on specific tabs, identified by their CssClass property. This script should prevent the default browser context menu. Capture the mouse position, and invoke a .NET [JSInvokable] method. |
14 | 71 |
|
15 | 72 | ## Files to Review |
16 | 73 |
|
17 | | -- link.cs (VB: link.vb) |
18 | | -- link.js |
19 | | -- ... |
| 74 | +- Index.razor |
| 75 | +- NavMenu.razor |
| 76 | +- MainLayout.razor |
| 77 | +- MDITab.cs |
| 78 | +- MDITabCollection.cs |
| 79 | +- MDIStateHelper.cs |
| 80 | +- mdi.js |
20 | 81 |
|
21 | 82 | ## Documentation |
22 | 83 |
|
23 | | -- link |
24 | | -- link |
25 | | -- ... |
| 84 | +- [DxTabs Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTabs) |
| 85 | +- [DxTabPage Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTabPage) |
| 86 | +- [DxContextMenu Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxContextMenu) |
| 87 | +- [DxContextMenuItem Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxContextMenuItem) |
26 | 88 |
|
27 | 89 | ## More Examples |
28 | 90 |
|
29 | | -- link |
30 | | -- link |
31 | | -- ... |
| 91 | +- [Form Layout for Blazor - Tabbed Wizard](https://github.com/DevExpress-Examples/Form-Layout-for-Blazor-Tabbed-Wizard) |
| 92 | + |
32 | 93 | <!-- feedback --> |
33 | 94 | ## Does this example address your development requirements/objectives? |
34 | 95 |
|
|
0 commit comments