Tag Archives: UXSliderBar

Use UXSliderBar to Simplify Data Entry

One of the powerful controls introduced in ClientUI 4 is UXSliderBar, an input control that enables users to select a value or range of values by sliding the UXThumb along the slider track through drag and drop operation in the thumb.

In this post, I will share how to use UXSliderBar to create a simple application to input grade for student.

Configuring the UXSliderBar

The scenario that I want to achieve is, create a sliderbar and set the value from 0 to 100. When user selects a value in the slider (let’s say 60, 85), the grade (A, B, C, D) will be displayed in the TextBox based on the selected value.

First of all, drag a UXSliderBar control from Visual Studio Toolbox. You need to configure its basic settings, such as Maximum, Minimum, SmallChange, and LargeChange.

Minimum and Maximum property indicates the possible lowet and highest value in the slider bar. SmallChange and LargeChange indicates the value to be added or subtracted from the value of UXSliderBar.

<Intersoft:UXSliderBar Minimum="0" Maximum="100" LargeChange="10"
                       SmallChange="1" TickPlacement="BottomRight"
                       HandlesVisibility="Visible"/>

UXSliderBar1

As you can see, the value becomes crowded because I want to display the value range from 0 to 100. This is where Ticks property is very useful. It is used to represent the position of the tick bar items displayed in the tick bar.

I’m going to set the ticks to 0, 55, 65, 75, 85. Therefore, the UXSliderBar will display something like following:

<Intersoft:UXSliderBar Minimum="0" Maximum="100" LargeChange="1"
                       SmallChange="0.1" TickPlacement="BottomRight"
                       HandlesVisibility="Visible" Ticks="0 55 65 75 85"/>

UXSliderBar2

In the case where the ticks are only displayed in specific positions, it is difficult to select a specific value, for example 79, in the slider bar. Using AutoTooltipVisibility property, you can display a tooltip containing the selected value when you drag the thumb. In addition, AutoTooltipFormat is used to set the format string applied to the content of the tooltip.

<Intersoft:UXSliderBar Minimum="0" Maximum="100" LargeChange="1"
                       SmallChange="1" TickPlacement="BottomRight"
                       HandlesVisibility="Visible" Ticks="0 55 65 75 85"
                       AutoTooltipVisibility="Visible"
                       AutoTooltipFormat="F0"/>

UXSliderBar3

Initially, when you bind the value from UXSliderBar into the Textbox control, it will only display the number. In this case, I want to show the Grade instead. Means that I need to add a converter in order to achieve this scenario.

Creating Grade Converter

In order to show the grade in Textbox, we need to bind slider’s value to Textbox and use data conversion to convert the grade into string.

Here is the code on how to bind the slider’s value to Textbox.

<TextBox Text="{Binding Value, ElementName=UXSliderBar1}" />

Now, you have successfully bound slider’s value to Textbox. But, in order to convert the number into string, you need to add a converter.

For more information on how to use a converter, please refer to Data Binding Overview on Data Conversion topic.

I create a class called GradeConverter.cs. In this class, I will create a converter by creating a class that inherits from IValueConverter and put a validation to convert the grade value into a string.

The GradeConverter.cs looks like the following:

using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace ClientUIMVVMBlogApp.Converters
{
    public class GradeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
                              object parameter,
                              System.Globalization.CultureInfo culture)
        {
            Double grade = (Double)value;
            String result = value.ToString();

            if (grade < 55)
            {
                result = "E";
            }

            else if (grade >= 55 && grade < 65)
            {
                result = "D";
            }

            else if (grade >= 65 && grade < 75)
            {
                result = "C";
            }

            else if (grade >= 75 && grade < 85)
            {
                result = "B";
            }

            else
            {
                result = "A";
            }
            return result;
        }

        public object ConvertBack(object value, Type targetType,
                                  object parameter,
                                  System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

Now, add the converter to the Textbox control that has been bound to the slider’s value:

<TextBox Text="{Binding Value, ElementName=UXSliderBar1,
                Converter={StaticResource GradeConverter}}"/>

There are some properties that you can optionally add to the UXSliderBar such ValueRangeVisibility and IsMoveToPointEnabled. ValueRangeVisibility is used to get/set whether the value range visual element is visible. You can see the value range visual element is in blue color.

IsMoveToPointEnabled is used to get/set a value that indicates whether the UXThumb moves immediately to the location of the mouse click that occurs while the mouse pointer pauses on the slider bar track.

Hence, the final code will look like following:

<StackPanel>
   <Intersoft:FieldLabel>
      <Intersoft:FieldLabel.Header>
         <TextBlock Text="Name :"/>
      </Intersoft:FieldLabel.Header>
      <TextBox Width="200" Text="John Doe"></TextBox>
   </Intersoft:FieldLabel>
   <Intersoft:FieldLabel>
      <Intersoft:FieldLabel.Header>
         <TextBlock Text="Grade :"/>
      </Intersoft:FieldLabel.Header>
      <StackPanel Orientation="Horizontal">
         <Intersoft:UXSliderBar Name="UXSliderBar1" Width="517"
                                Minimum="0" Maximum="100" LargeChange="1"
                                SmallChange="0.1" TickPlacement="BottomRight"
                                HandlesVisibility="Visible"
                                ValueRangeVisibility="Visible" Value="55"
                                AutoTooltipVisibility="Visible"
                                AutoTooltipFormat="F0" Ticks="0 55 65 75 85"
                                IsMoveToPointEnabled="True" Height="50" />
         <TextBox Height="27" Width="33" HorizontalAlignment="Left"
                  Text="{Binding Value, ElementName=UXSliderBar1,
                         Converter={StaticResource GradeConverter}}"/>
      </StackPanel>
   </Intersoft:FieldLabel>
</StackPanel>

When you run the project, the final results will look like the following illustration.
UXSliderBar control

When you drag the slider bar to determine the value, it will automatically convert the value into string, and place the grade into the Textbox.

Summary

In this post, you have learned how to initially create UXSliderBar and configure its basic settings. You also have been guided on how to create data conversion and bind it to a Textbox control.

For more information about the scenario, you can download the sample here. To see all available features, see UXSliderBar Overview. If you have questions or feedback about UXSliderBar or other ClientUI controls, please feel free to post them to our Community Forum.

Regards,

-Martin-

New in ClientUI 4: Intuitive Slider Bar Control

ClientUI 4 is the latest version of our flagship development suite for the Silverlight and WPF platform. To learn more about ClientUI, you can read this post or visit ClientUI product information here. To see what’s new in ClientUI 4, see this article.

Introducing UXSliderBar

UXSliderBar is one of the new controls included in ClientUI 4. UXSliderBar is mainly used to select a value from a range of values by moving the thumb along the slider bar track area.

For example: in the following property finder scenario, users can select a property size starts from 500 to 1000 square feet. Surely, you can use textbox to input the property size that you want. However, there are at least two advantages for using UXSliderBar. First, users will automatically know the range of property size available and easily select a value by moving the thumb. Second, you, as developer, can prevent users from inputting the wrong value in the textbox and thus, eliminate the needs to implement input type validation, should textbox is used instead.

Blog1

<StackPanel>
    <TextBlock FontSize="26">Property Finder</TextBlock>
    <Intersoft:FieldLabel>
        <Intersoft:FieldLabel.Header>
            <TextBlock Width="100" TextWrapping="Wrap" 
                       Text="Select Size (in sq ft.)"></TextBlock>
        </Intersoft:FieldLabel.Header>
            <Intersoft:UXSliderBar Width="400" TickPlacement="BottomRight" 
                                   Minimum="500" Maximum="1000"                                    
                                   LargeChange="100" SmallChange="10" 
                                   IsMoveToPointEnabled="True" 
                                   Value="{Binding 
                                   PropertyFinder.PropertySize, 
                                   Mode=TwoWay, ValidatesOnDataErrors=True, 
                                   ValidatesOnExceptions=True}"/>
    </Intersoft:FieldLabel>
    <Intersoft:FieldLabel>
        <Intersoft:FieldLabel.Header>
            <TextBlock Width="100" TextWrapping="Wrap" 
                       Text="Select Price (in 1000 USD)"></TextBlock>
        </Intersoft:FieldLabel.Header>
        <Intersoft:UXRangeSliderBar Width="400" TickPlacement="BottomRight" 
                                    TickFormat="C0" Minimum="100" 
                                    Maximum="700" LargeChange="100" 
                                    SmallChange="10" 
                                    SelectionStart="{Binding 
                                    PropertyFinder.StartPrice, 
                                    Mode=TwoWay, ValidatesOnDataErrors=True, 
                                    ValidatesOnExceptions=True}"
                                    SelectionEnd="{Binding 
                                    PropertyFinder.EndPrice,
                                    Mode=TwoWay, ValidatesOnDataErrors=True, 
                                    ValidatesOnExceptions=True}"/>
    </Intersoft:FieldLabel>
    <Button Content="Search" Width="100" Margin="0, 20, 0, 0"></Button>
</StackPanel>

You might note that UXRangeSliderBar is used in this scenario, but we’ll discuss about that in the next post 🙂

I’ve mentioned that you can easily select a value in UXSliderBar by moving the thumb along the slider bar track area. Besides that, you can use a variation of keyboard keys registered to UXSliderBar commands or click the slider bar track area and handle buttons. These user interactions will use the value of LargeChange and SmallChange properties specified in UXSliderBar.

  • Use keyboard keys.

    Some key gestures are already registered to UXSliderBar commands. When you press Up, Down, Left, or Right keys, the value of UXSliderBar will be added or subtracted with the value of SmallChange property. For example: in the above scenario, the value of UXSliderBar is 700.When you press the Right key, the value of UXSliderBar will be added with the value of SmallChange property, which is 10. So, the value of UXSliderBar now is 710.

    When you press PageUp or PageDown keys, the value of UXSliderBar will be added or subtracted with the value of LargeChange property. So, if the value of UXSliderBar is 710 and you press the PageDown key, the value of UXSliderBar will be subtracted with the value of LargeChange property, 100. So, the value of UXSliderBar now is 610.

    When you press Home or End key, the value of UXSliderBar will be set to the Minimum or Maximum property respectively. If you press End key, the value of UXSliderBar will be set to 1000 and the thumb will move to the end of the slider bar.

  • Click the slider bar track area.

    You can also click the track area at the left or right side of the thumb. When you click the blue area, known as DecreaseButton, the value of UXSliderBar will be subtracted with the value of LargeChange property. When you click the purple area, known as IncreaseButton, the value of UXSliderBar will be added with the value of LargeChange property.

    Blog2

  • Click the handle buttons.

    By default the handle buttons are not displayed in UXSliderBar. To display the handle buttons, you can set HandlesVisibility to Visible. Two arrow-shaped buttons will be displayed at the left and right side of UXSliderBar.

    When you click the handle buttons, the value of UXSliderBar will be added or subtracted with the value of SmallChange property.

    Blog3

Enabling Snap to Tick Behavior

When moving thumb to select a value, it is possible that you select a fractional value, such as: 700.346, which is rather uncommon for a property size. I think you would want a rounded value for that, right? In this case, you can enable IsSnapToTickEnabled property.

<Intersoft:UXSliderBar Width="400" TickPlacement="BottomRight" Minimum="500" 
                       Maximum="1000" LargeChange="100" SmallChange="10"                                                                      IsSnapToTickEnabled="True" Value="{Binding 
                       PropertyFinder.PropertySize, Mode=TwoWay, 
                       ValidatesOnDataErrors=True, 
                       ValidatesOnExceptions=True}"/>

When this property is enabled, the thumb will move to the closest tickbar item. So, as you move the thumb to the right, it will snap to 600, 700, 800, and so on.

When snap to tick behavior is enabled, you can still enable precision selection by pressing Ctrl key. Try to move the thumb while pressing the Ctrl key. The thumb will not snap to the closest tickbar item, but moves along with the cursor position, as if this behavior is not enabled.

Enabling Move to Point Behavior

Now, what if I want to select 900 as the property size? This might be what you think; either moves the thumb, press Up key several times, or click the track area continuously. Well, let me save your time a bit by introducing IsMoveToPointEnabled property.

<Intersoft:UXSliderBar Width="400" TickPlacement="BottomRight" Minimum="500" 
                       Maximum="1000" LargeChange="100" SmallChange="10"                                               IsMoveToPointEnabled="True" Value="{Binding 
                       PropertyFinder.PropertySize, Mode=TwoWay, 
                       ValidatesOnDataErrors=True, 
                       ValidatesOnExceptions=True}"/>

When this property is enabled, you can click on any position in the slider bar track area and the thumb will move immediately to the location of the click. You can click on 900 tickbar item and the thumb will move immediately there.

Well, I understand clicking right on the tickbar item will not be that easy and I probably would need a couple of try for that. That is the reason why you should enable both snap to tick and move to point behavior. When these properties are enabled, you can click near the tickbar item and the thumb will snap to it.

Enabling Auto Tooltip

While moving the thumb along the slider bar track area, you might find it difficult to determine what value you are hovering. You can display a tooltip near the thumb that contains the value of the hovered position using AutoTooltipVisibility property. You can specify AutoTooltipPosition, AutoTooltipFormat, AutoTooltipHorizontalDirection, and AutoTooltipVerticalDirection for additional configuration.

Let’s say you want to select a discount value using UXSliderBar. You can display the percentage value you’re selecting in the tooltip.

<Intersoft:UXSliderBar TickPlacement="BottomRight" TickFormat="P0" 
                       Maximum="1" LargeChange="0.2" 
                       AutoTooltipVisibility="Visible" 
                       AutoTooltipFormat="P0"/>

Blog4

Displaying Value Range Track

In the discount slider bar, it can be useful to display the active selection track. You can see how much discount applied to a product simply by seeing the value range track. In UXSliderBar, the value range track is indicated by a blue-colored track that starts from the value of Minimum property to the selected value of UXSliderBar. You can display the value range track using ValueRangeVisibility property.

<Intersoft:UXSliderBar TickPlacement="BottomRight" TickFormat="P0" 
                       Maximum="1" LargeChange="0.2" 
                       ValueRangeVisibility="Visible" 
                       Value="0.5"/>

Blog5

Conclusion

In this post, you have learned the various ways to change the value of UXSliderBar, the behaviors related to it, the auto tooltip, and the value range track.

To try it out yourself, feel free to browse through the samples here. To see all available features in UXSliderBar, see UXSliderBar Overview. If you have questions or feedback about UXSliderBar, feel free to post them to our community forum.

Cheers,

Erika