Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BlazorSlider/BlazorSlider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
</Target>

<ItemGroup>
<PackageReference Include="DevExpress.Blazor" Version="25.1.*" />
<PackageReference Include="DevExpress.Blazor" Version="25.2.*" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions BlazorSlider/Components/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
<DxFormLayoutItem ColSpanXs="12" Caption="Default mode">
<DxSlider T="int" MinValue="0" MaxValue="100" Value="90" />
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanXs="12" Caption="With labels">
<DxFormLayoutItem ColSpanXs="12" Caption="Labels Enabled">
<DxSlider T="int" MinValue="0" MaxValue="100" Value="50">
<DxSliderLabelSettings Visible="true"
Position="VerticalEdge.Top" />
</DxSlider>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanXs="12" Caption="With tooltip">
<DxFormLayoutItem ColSpanXs="12" Caption="Tooltips Enabled">
<DxSlider T="int" MinValue="0" MaxValue="100" Value="35">
<DxSliderTooltipSettings Enabled="true"
ShowMode="TooltipShowMode.Always"
Position="VerticalEdge.Bottom" />
</DxSlider>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanXs="12" Caption="Without range highlighting">
<DxFormLayoutItem ColSpanXs="12" Caption="Range Highlight Disabled">
<DxSlider T="int" MinValue="0" MaxValue="100"
Value="20" ShowRange="false" />
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanXs="12" Caption="With discrete step">
<DxFormLayoutItem ColSpanXs="12" Caption="Discrete Step Enabled">
<DxSlider T="int" MinValue="0" MaxValue="100" Value="10" Step="10">
<DxSliderTooltipSettings Enabled="true" />
</DxSlider>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanXs="12" Caption="Disabled">
<DxFormLayoutItem ColSpanXs="12" Caption="Disabled Mode">
<DxSlider T="int" MinValue="0" MaxValue="100"
Value="50" Enabled="false" />
</DxFormLayoutItem>
Expand Down
8 changes: 4 additions & 4 deletions BlazorSlider/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion BlazorSlider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "asp.net",
"private": true,
"devDependencies": {
"devextreme-dist": "~25.1"
"devextreme-dist": "25.2.3"
}
}
8 changes: 4 additions & 4 deletions BlazorSlider/wwwroot/css/dx.fluent.blue.light.css

Large diffs are not rendered by default.

85 changes: 71 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,91 @@
<!-- default badges list -->
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/1113565705/25.2.3%2B)
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1319057)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
<!-- default badges end -->
# Product/Platform - Task
# Blazor - Use DevExtreme Slider in Blazor Applications

This is the repository template for creating new examples. Describe the solved task here.
This example adds the [DevExtreme Slider widget]() to a Blazor application. The example replicates the [DevExtreme jQuery Slider](https://js.devexpress.com/jQuery/Demos/WidgetsGallery/Demo/Slider/Overview/FluentBlueLight/) demo and showcases the following features and capabilities:
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

Put a screenshot that illustrates the result here.
* Min and max labels
* Tooltip customization
* Range highlight
* Discrete steps
* Disabled component state
* Dynamic value changes
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

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.
![DevExtreme Slider in DevExpress Blazor App](sliders.png)
Comment thread
elenapeskova marked this conversation as resolved.

The DevExpress Blazor UI Component Library includes multiple DevExtreme-based components (for example, [DxHtmlEditor](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxHtmlEditor) or [DxMap](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxMap)). Refer to class descriptions for additional information.
Comment thread
elenapeskova marked this conversation as resolved.
Outdated
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

Comment thread
elenapeskova marked this conversation as resolved.
Outdated
## Implementation Details

### Register DevExtreme Resources

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 deliver DevExtreme to the application.
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

The DevExpress Blazor [Resource Manager](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxResourceManager) automatically registers the DevExtreme script 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) file.
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

### Implement a Wrapper

Implement a Blazor component that wraps the DevExtreme Slider widget. The wrapper consists of the following files (copy them to your application):
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

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.
2. [DxSliderLabelSettings.razor](./BlazorSlider/Components/Slider/DxSliderLabelSettings.razor) and [DxSliderTooltipSettings.razor](./BlazorSlider/Components/Slider/DxSliderTooltipSettings.razor) configure slider label and tooltip settings.
3. [DxSlider.razor.js](./BlazorSlider/Components/Slider/DxSlider.razor.js) binds the DevExtreme Slider component to the data model.
4. [DxSlider.razor](./BlazorSlider/Components/Slider/DxSlider.razor) wraps and renders the Slider:
Comment thread
elenapeskova marked this conversation as resolved.
Outdated
* Declares a `CascadingValue` component and uses a `ChildContent` parameter to customize slider labels and tooltips via Blazor parameters:
Comment thread
elenapeskova marked this conversation as resolved.
Outdated
```Razor
<CascadingValue IsFixed="true" Value="sliderState">
@ChildContent
<div @ref="sliderElement"></div>
</CascadingValue>
```
* 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.
Comment thread
elenapeskova marked this conversation as resolved.
```cs
protected override async Task OnAfterRenderAsync(bool firstRender) {
if(firstRender) {
await JS.LoadDxResources();
clientModule = await LoadSliderModule();
clientSlider = await LoadClientInstance(clientModule);
}
}
```
Comment thread
elenapeskova marked this conversation as resolved.
Outdated
* 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.
Comment thread
elenapeskova marked this conversation as resolved.
* In the [UpdateValueFromClient](./BlazorSlider/Components/Slider/DxSlider.razor#L85-L91) method, synchronizes the server-side state with slider client-side value changes.

### Render the Blazor Component
Comment thread
elenapeskova marked this conversation as resolved.
Outdated

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.

```Razor
<DxSlider T="int" MinValue="0" MaxValue="100" Value="50">
<DxSliderLabelSettings Visible="true"
Position="VerticalEdge.Top" />
</DxSlider>
```

## Files to Review

- link.cs (VB: link.vb)
- link.js
- ...
- [DxSlider.razor](/BlazorSlider/Components/Slider/DxSlider.razor)
- [DxSlider.razor.js](/BlazorSlider/Components/Slider/DxSlider.razor.js)
- [DxSliderLabelSettings.razor](/BlazorSlider/Components/Slider/DxSliderLabelSettings.razor)
- [DxSliderTooltipSettings.razor](/BlazorSlider/Components/Slider/DxSliderTooltipSettings.razor)
- [SliderState.cs](/BlazorSlider/Components/Slider/SliderState.cs)
- [App.razor](/BlazorSlider/Components/App.razor)
- [Index.razor](/BlazorSlider/Components/Pages/Index.razor)

## Documentation

- link
- link
- ...
- [Add DevExtreme Components to a Blazor Application](https://docs.devexpress.com/Blazor/403578/components/devextreme-components-in-blazor)
- [Get Started with DevExtreme jQuery/JS](https://js.devexpress.com/jQuery/Documentation/Guide/Common/First_Steps/)
- [DevExtreme JavaScript/jQuery Slider](https://js.devexpress.com/jQuery/Documentation/Guide/UI_Components/Slider/Overview/)

## More Examples

- link
- link
- ...
- [Blazor - Use DevExtreme Circular Gauge in a Blazor Application](https://github.com/DevExpress-Examples/blazor-use-devextreme-circular-gauge)
- [Blazor - Use DevExtreme Diagram in Blazor Applications](https://github.com/DevExpress-Examples/blazor-use-devextreme-diagram)

<!-- feedback -->
## Does this example address your development requirements/objectives?

Expand Down
Binary file added sliders.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.