Skip to content

Commit abf7987

Browse files
committed
Tabbed UI example fixes and readme
1 parent d814f7e commit abf7987

File tree

11 files changed

+108
-29
lines changed

11 files changed

+108
-29
lines changed

CS/DxBlazorApplication1/Components/Layout/MainLayout.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
private RenderFragment drawerHeader => @<div class="navigation-drawer-header">
3030
<img class="logo" src="images/logo.svg" alt="DevExpress logo" />
3131
<NavLink href="@UrlGenerator.GetUrl(new Uri(NavigationManager.Uri).LocalPath, !ToggledSidebar)">
32-
<DxButton RenderStyle="@ButtonRenderStyle.Light" RenderStyleMode="@ButtonRenderStyleMode.Text" CssClass="menu-button-nav" IconCssClass="@(ToggledSidebar ? "icon icon-close" : "icon icon-menu")"></DxButton>
3332
</NavLink>
3433
</div>;
3534

CS/DxBlazorApplication1/Components/Layout/NavMenu.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Items>
44
<DxMenuItem Name="Counter" Text="Counter" CssClass="menu-item" IconCssClass="icon counter-icon"></DxMenuItem>
55
<DxMenuItem Name="Weather" Text="Weather" CssClass="menu-item" IconCssClass="icon weather-icon"></DxMenuItem>
6-
<DxMenuItem Name="Forms" Text="Forms" CssClass="menu-item" IconCssClass="icon weather-icon"></DxMenuItem>
6+
<DxMenuItem Name="Form" Text="Form" CssClass="menu-item" IconCssClass="icon form-icon"></DxMenuItem>
77
</Items>
88
</DxMenu>
99
</div>

CS/DxBlazorApplication1/Components/Layout/NavMenu.razor.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
background-image: url("images/weather.svg");
4949
}
5050

51+
::deep .form-icon {
52+
background-image: url("images/form.svg");
53+
}
54+
5155
::deep .counter-icon {
5256
background-image: url("images/counter.svg");
5357
}

CS/DxBlazorApplication1/Components/Pages/Counter.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@page "/counter"
22
@rendermode InteractiveServer
3-
<PageTitle>Counter</PageTitle>
43

54
<h1>Counter</h1>
65

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "/forms"
1+
@page "/form"
22

33
<style>
44
.my-form{
@@ -11,16 +11,17 @@
1111
<DxTextBox></DxTextBox>
1212
</DxFormLayoutItem>
1313
<DxFormLayoutItem Caption="Age">
14-
<DxSpinEdit T="int"></DxSpinEdit>
15-
</DxFormLayoutItem>
16-
<DxFormLayoutItem Caption="DOB">
17-
<DxDateEdit T="DateTime"></DxDateEdit>
14+
<DxSpinEdit T="int" MinValue="0"></DxSpinEdit>
1815
</DxFormLayoutItem>
1916
<DxFormLayoutItem Caption="Hobbies">
2017
<DxTagBox TData="string" TValue="string"
2118
Data="@(new List<string>(){"Swimming", "Hiking", "Chess"})"></DxTagBox>
2219
</DxFormLayoutItem>
23-
<DxFormLayoutItem ColSpanMd="12" Caption="Photo">
24-
<DxFileInput></DxFileInput>
20+
<DxFormLayoutItem BeginRow="true">
21+
<DxFileInput SelectButtonText="Add a Photo"></DxFileInput>
2522
</DxFormLayoutItem>
2623
</DxFormLayout>
24+
25+
@code {
26+
DateTime Today = DateTime.Today;
27+
}

CS/DxBlazorApplication1/Components/Pages/Index.razor

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
@inject IJSRuntime JS
55
@inject MDIStateHelper StateHelper
66

7+
<PageTitle>Multi-Tab Interface</PageTitle>
8+
79
<div @ref=divContainer>
810
<DxTabs @ref=tabs
911
@bind-ActiveTabIndex=activeTabIndex
@@ -12,13 +14,19 @@
1214
TabClosing="OnTabClosing"
1315
RenderMode="TabsRenderMode.AllTabs">
1416
<DxTabPage CssClass="counter-tab" AllowClose="true" VisibleIndex="@collection.GetVisibleIndexByTabText("Counter")" Visible="@collection.GetVisibleByTabText("Counter")" Text="Counter">
15-
<Counter></Counter>
17+
<div class="tab-body">
18+
<Counter />
19+
</div>
1620
</DxTabPage>
1721
<DxTabPage CssClass="weather-tab" AllowClose="true" VisibleIndex="@collection.GetVisibleIndexByTabText("Weather")" Visible="@collection.GetVisibleByTabText("Weather")" Text="Weather">
18-
<Weather></Weather>
22+
<div class="tab-body">
23+
<Weather />
24+
</div>
1925
</DxTabPage>
20-
<DxTabPage CssClass="forms-tab" AllowClose="true" VisibleIndex="@collection.GetVisibleIndexByTabText("Forms")" Visible="@collection.GetVisibleByTabText("Forms")" Text="Forms">
21-
<Forms></Forms>
26+
<DxTabPage CssClass="form-tab" AllowClose="true" VisibleIndex="@collection.GetVisibleIndexByTabText("Form")" Visible="@collection.GetVisibleByTabText("Form")" Text="Form">
27+
<div class="tab-body">
28+
<Form />
29+
</div>
2230
</DxTabPage>
2331
</DxTabs>
2432
</div>

CS/DxBlazorApplication1/Components/Pages/Index.razor.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
::deep .welcome-gridlayout {
1+
.tab-body {
2+
padding: 20px 16px;
3+
}
4+
5+
::deep .welcome-gridlayout {
26
margin: auto;
37
width: auto;
48
height: auto;

CS/DxBlazorApplication1/Components/Pages/Weather.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
@rendermode InteractiveServer
66
@inject WeatherForecastService ForecastService
77

8-
<PageTitle>Weather</PageTitle>
98
<h1>Weather</h1>
109

1110
@if (forecasts == null)
Lines changed: 3 additions & 0 deletions
Loading

README.md

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,93 @@
44
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
55
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
66
<!-- default badges end -->
7-
# Product/Platform - Task
7+
# Blazor Tabs - Create a Dynamic Tabbed Interface
88

9-
This is the repository template for creating new examples. Describe the solved task here.
9+
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.
1010

11-
Put a screenshot that illustrates the result here.
11+
![Multi-Tab UI](images/blazor-tabbed-ui.png)
1212

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.
13+
It showcases core features that help end users build their personalized workspaces and multitask effectively.
14+
15+
### Organize Content Into Tabs
16+
17+
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.
18+
19+
Insert your custom Blazor components or content directly into each DxTabPage.
20+
21+
```razor
22+
<DxTabs @ref=tabs
23+
@bind-ActiveTabIndex=activeTabIndex
24+
AllowTabReorder="true"
25+
TabReordering="OnTabReordering"
26+
TabClosing="OnTabClosing"
27+
RenderMode="TabsRenderMode.AllTabs">
28+
<DxTabPage CssClass="counter-tab"
29+
AllowClose="true"
30+
VisibleIndex="@collection.GetVisibleIndexByTabText("Counter")"
31+
Visible="@collection.GetVisibleByTabText("Counter")"
32+
Text="Counter">
33+
<div class="tab-body">
34+
<Counter />
35+
</div>
36+
</DxTabPage>
37+
```
38+
39+
The CssClass property of a tab page serves as a unique identifier, allowing client-side scripts to interact with specific tabs.
40+
41+
### Persist Tab State
42+
43+
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.
44+
45+
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.
46+
47+
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.
48+
49+
### Add Context Menu to Tabs
50+
51+
Create a context menu that allows users to manage tabs:
52+
53+
- Close the current tab.
54+
- Close all tabs.
55+
- Close all tabs except for the current one.
56+
- Restore closed tabs.
57+
58+
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.
59+
60+
```razor
61+
<DxContextMenu @ref=menu>
62+
<Items>
63+
<DxContextMenuItem Click="CloseTab" Text="Close"></DxContextMenuItem>
64+
<DxContextMenuItem Click="CloseAllTabs" Text="Close All Tabs"></DxContextMenuItem>
65+
<DxContextMenuItem Click="CloseOtherTabs" Text="Close Other Tabs"></DxContextMenuItem>
66+
<DxContextMenuItem Click="RestoreAllTabs" Text="Restore Closed Tabs"></DxContextMenuItem>
67+
</Items>
68+
</DxContextMenu>
69+
```
70+
71+
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.
1472

1573
## Files to Review
1674

17-
- link.cs (VB: link.vb)
18-
- link.js
19-
- ...
75+
- Index.razor
76+
- NavMenu.razor
77+
- MainLayout.razor
78+
- MDITab.cs
79+
- MDITabCollection.cs
80+
- MDIStateHelper.cs
81+
- mdi.js
2082

2183
## Documentation
2284

23-
- link
24-
- link
25-
- ...
85+
- [DxTabs Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTabs)
86+
- [DxTabPage Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTabPage)
87+
- [DxContextMenu Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxContextMenu)
88+
- [DxContextMenuItem Class](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxContextMenuItem)
2689

2790
## More Examples
2891

29-
- link
30-
- link
31-
- ...
92+
- [Form Layout for Blazor - Tabbed Wizard](https://github.com/DevExpress-Examples/Form-Layout-for-Blazor-Tabbed-Wizard)
93+
3294
<!-- feedback -->
3395
## Does this example address your development requirements/objectives?
3496

0 commit comments

Comments
 (0)