|
1 | 1 | <!-- default badges list --> |
2 | | - |
3 | 2 | [](https://supportcenter.devexpress.com/ticket/details/T1319057) |
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 - Use DevExtreme Slider in Blazor Applications |
8 | 7 |
|
9 | | -This is the repository template for creating new examples. Describe the solved task here. |
| 8 | +This example adds a [DevExtreme Slider widget](https://js.devexpress.com/jQuery/Documentation/Guide/UI_Components/Slider/Overview/) to a Blazor application and showcases the following features and capabilities: |
10 | 9 |
|
11 | | -Put a screenshot that illustrates the result here. |
| 10 | +* Min and max labels |
| 11 | +* Tooltip customization |
| 12 | +* Range highlight |
| 13 | +* Discrete steps |
| 14 | +* Disabled component state |
| 15 | +* Dynamic value updates |
12 | 16 |
|
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. |
| 17 | +The example replicates the [DevExtreme jQuery Slider](https://js.devexpress.com/jQuery/Demos/WidgetsGallery/Demo/Slider/Overview/FluentBlueLight/) demo. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +## Implementation Details |
| 22 | + |
| 23 | +### Register DevExtreme Resources |
| 24 | + |
| 25 | +DevExtreme widgets require the use of [DevExtreme scripts and stylesheets](https://js.devexpress.com/jQuery/Documentation/Guide/jQuery_Components/Add_DevExtreme_to_a_jQuery_Application/#Local_Files). We recommend that you use [npm](https://js.devexpress.com/jQuery/Documentation/Guide/Common/Distribution_Channels/#npm) to incorporate DevExtreme into the application. |
| 26 | + |
| 27 | +The DevExpress Blazor [Resource Manager](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxResourceManager) automatically registers DevExtreme scripts if your project includes the `DevExpress.Blazor` package. To apply the DevExtreme Fluent theme, add the [dx.fluent.blue.light.css](./BlazorSlider/wwwroot/css/dx.fluent.blue.light.css) file to the [wwwroot/css](./BlazorSlider/wwwroot/css/) folder and reference this stylesheet in the [Components/App.razor](./BlazorSlider/Components/App.razor#L12) file. |
| 28 | + |
| 29 | +### Implement a Wrapper |
| 30 | + |
| 31 | +Implement a Blazor component that wraps the DevExtreme Slider widget. The wrapper consists of the following files (copy them to your solution): |
| 32 | + |
| 33 | +1. [SliderState.cs](./BlazorSlider/Components/Slider/SliderState.cs) defines a data model that stores slider properties. The model is passed to razor components via cascading parameters to initialize slider states in their `OnInitialized` lifecycle methods. |
| 34 | +2. [DxSliderLabelSettings.razor](./BlazorSlider/Components/Slider/DxSliderLabelSettings.razor) and [DxSliderTooltipSettings.razor](./BlazorSlider/Components/Slider/DxSliderTooltipSettings.razor) configure slider label and tooltip settings. |
| 35 | +3. [DxSlider.razor.js](./BlazorSlider/Components/Slider/DxSlider.razor.js) binds the DevExtreme Slider component to the data model. |
| 36 | +4. [DxSlider.razor](./BlazorSlider/Components/Slider/DxSlider.razor) renders the Slider as follows: |
| 37 | + * Declares a `CascadingValue` component and uses `ChildContent` to customize slider labels and tooltips using Blazor parameters: |
| 38 | + ```Razor |
| 39 | + <CascadingValue IsFixed="true" Value="sliderState"> |
| 40 | + @ChildContent |
| 41 | + <div @ref="sliderElement"></div> |
| 42 | + </CascadingValue> |
| 43 | + ``` |
| 44 | + * In the `OnAfterRenderAsync` lifecycle method, calls the [LoadDxResources](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxResourceManager.LoadDxResources(Microsoft.JSInterop.IJSRuntime)) method to force the `Resource Manager` to load all client scripts. |
| 45 | + * In the [OnParametersSetAsync](./BlazorSlider/Components/Slider/DxSlider.razor#L57-L64) lifecycle method, updates the internal model state and rerenders the slider component once Blazor parameters change. |
| 46 | + * In the [UpdateValueFromClient](./BlazorSlider/Components/Slider/DxSlider.razor#L85-L91) method, synchronizes the server-side state with slider client-side value changes. |
| 47 | +
|
| 48 | +### Display a Blazor Component |
| 49 | +
|
| 50 | +Use the wrapper as a standard Blazor component. This example adds the [DevExpress Blazor FormLayout](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxFormLayout) component to the [Index.razor](./BlazorSlider/Components/Pages/Index.razor) file and declares `DxSlider` objects within layout items to display various slider states and capabilities. |
| 51 | +
|
| 52 | +```Razor |
| 53 | +<DxSlider T="int" MinValue="0" MaxValue="100" Value="50"> |
| 54 | + <DxSliderLabelSettings Visible="true" |
| 55 | + Position="VerticalEdge.Top" /> |
| 56 | +</DxSlider> |
| 57 | +``` |
14 | 58 |
|
15 | 59 | ## Files to Review |
16 | 60 |
|
17 | | -- link.cs (VB: link.vb) |
18 | | -- link.js |
19 | | -- ... |
| 61 | +- [DxSlider.razor](/BlazorSlider/Components/Slider/DxSlider.razor) |
| 62 | +- [DxSlider.razor.js](/BlazorSlider/Components/Slider/DxSlider.razor.js) |
| 63 | +- [DxSliderLabelSettings.razor](/BlazorSlider/Components/Slider/DxSliderLabelSettings.razor) |
| 64 | +- [DxSliderTooltipSettings.razor](/BlazorSlider/Components/Slider/DxSliderTooltipSettings.razor) |
| 65 | +- [SliderState.cs](/BlazorSlider/Components/Slider/SliderState.cs) |
| 66 | +- [App.razor](/BlazorSlider/Components/App.razor) |
| 67 | +- [Index.razor](/BlazorSlider/Components/Pages/Index.razor) |
20 | 68 |
|
21 | 69 | ## Documentation |
22 | 70 |
|
23 | | -- link |
24 | | -- link |
25 | | -- ... |
| 71 | +- [Add DevExtreme Components to a Blazor Application](https://docs.devexpress.com/Blazor/403578/components/devextreme-components-in-blazor) |
| 72 | +- [Get Started with DevExtreme jQuery/JS](https://js.devexpress.com/jQuery/Documentation/Guide/Common/First_Steps/) |
| 73 | +- [DevExtreme JavaScript/jQuery Slider](https://js.devexpress.com/jQuery/Documentation/Guide/UI_Components/Slider/Overview/) |
26 | 74 |
|
27 | 75 | ## More Examples |
28 | 76 |
|
29 | | -- link |
30 | | -- link |
31 | | -- ... |
| 77 | +- [Blazor - Use DevExtreme Circular Gauge in a Blazor Application](https://github.com/DevExpress-Examples/blazor-use-devextreme-circular-gauge) |
| 78 | +- [Blazor - Use DevExtreme Diagram in Blazor Applications](https://github.com/DevExpress-Examples/blazor-use-devextreme-diagram) |
| 79 | + |
32 | 80 | <!-- feedback --> |
33 | 81 | ## Does this example address your development requirements/objectives? |
34 | 82 |
|
|
0 commit comments