|
| 1 | +--- |
| 2 | +title: Add Multiple Labels in a Blazor ProgressBar |
| 3 | +description: Learn how to display two or more labels in a ProgressBar for Blazor. |
| 4 | +type: how-to |
| 5 | +page_title: How to Add Multiple Labels in a Blazor ProgressBar |
| 6 | +slug: progressbar-kb-add-multiple-labels |
| 7 | +tags: progressbar, blazor, label, template, css |
| 8 | +res_type: kb |
| 9 | +ticketid: 1659413 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>ProgressBar for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +I want to display two labels on my ProgressBar component: one on the left side to show the current progress and another on the right side for the remaining value. |
| 26 | + |
| 27 | +This KB article also answers the following questions: |
| 28 | + |
| 29 | +- How can I customize the label inside a ProgressBar in Blazor? |
| 30 | +- Is it possible to display two or more labels in a ProgressBar? |
| 31 | +- How do I use the label template feature in the ProgressBar for Blazor? |
| 32 | + |
| 33 | +## Solution |
| 34 | + |
| 35 | +To display two or more labels in a [ProgressBar]({%slug progressbar-overview%}) for Blazor, use the [Label Template]({%slug progressbar-label%}#template): |
| 36 | +1. Declare the `Template` inside the `ProgressBarLabel` label tag. |
| 37 | +1. Add your desired labels in separate HTML containers. |
| 38 | +1. Use CSS to position them based on your preferences. |
| 39 | + |
| 40 | +The code snippet below creates a ProgressBar with a custom label that includes two spans: one for the current value and another for the remaining value. The labels are positioned on the left and right sides of the ProgressBar, respectively, using CSS Flexbox for layout. |
| 41 | + |
| 42 | +````CSHTML |
| 43 | +<TelerikProgressBar Value="@PBValue" |
| 44 | + Max="@MaxValue" |
| 45 | + Class="two-labels-progressbar"> |
| 46 | + <ProgressBarLabel Visible="true" Position="@ProgressBarLabelPosition.Center"> |
| 47 | + <Template> |
| 48 | + <div class="label-container"> |
| 49 | + <span>Current value: @(context.Value)%</span> |
| 50 | + <span>Remaining: @(MaxValue - context.Value)%</span> |
| 51 | + </div> |
| 52 | + </Template> |
| 53 | + </ProgressBarLabel> |
| 54 | +</TelerikProgressBar> |
| 55 | +
|
| 56 | +<style> |
| 57 | + .two-labels-progressbar { |
| 58 | + width: 700px; |
| 59 | + } |
| 60 | +
|
| 61 | + .two-labels-progressbar .label-container { |
| 62 | + width: 680px; |
| 63 | + display: flex; |
| 64 | + justify-content: space-between; |
| 65 | + } |
| 66 | +</style> |
| 67 | +
|
| 68 | +@code { |
| 69 | + private double MaxValue { get; set; } = 50; |
| 70 | + private double PBValue { get; set; } = 10; |
| 71 | +} |
| 72 | +```` |
| 73 | + |
| 74 | +## See Also |
| 75 | + |
| 76 | +* [ProgressBar Label Documentation]({%slug progressbar-label%}) |
0 commit comments