Intersoft ClientUI 8 > ClientUI Controls > Control Library > Advanced Input Controls Overview > UXSliderBar > How-to: Validate Value in UXSliderBar |
This example shows how to validate the value in UXSliderBar.
As an input control, you can enable data validation in UXSliderBar. When the value of UXSliderBar is bound to a data entity, you can throw an exception when the data is invalid.
The following code example shows how to validate the value in UXSliderBar using MVVM pattern.
Model |
Copy Code
|
---|---|
using ClientUI.Samples.ViewModels; namespace ClientUI.Samples.Models { public class PropertyFinder : ModelBase { public PropertyFinder() { } public bool EnableValidation { get; set; } private double _propertySize; public double PropertySize { get { return _propertySize; } set { if (_propertySize != value) { _propertySize = value; ClearError("PropertySize"); if (EnableValidation && (double.IsNaN(this.PropertySize) || this.PropertySize < 600.0)) SetError("PropertySize", "Property size must not be smaller than 600 sq ft."); OnPropertyChanged("PropertySize"); } } } } } |
View Model |
Copy Code
|
---|---|
using ClientUI.Samples.Models; namespace ClientUI.Samples.ViewModels { public class PropertyFinderViewModel: ValidationViewModelBase { private PropertyFinder _propertyFinder; // Constructor public PropertyFinderViewModel() { this.PropertyFinder = new PropertyFinder { PropertySize = 700 }; this.PropertyFinder.EnableValidation = true; } // Views public PropertyFinder PropertyFinder { get { return this._propertyFinder; } set { if (this._propertyFinder != value) { this._propertyFinder = value; OnPropertyChanged("PropertyFinder"); } } } } } |
View |
Copy Code
|
---|---|
<UserControl x:Class="ClientUI.Samples.Views.PropertyFinder" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Intersoft="http://intersoft.clientui.com/schemas" xmlns:ViewModels="clr-namespace:ClientUI.Samples.ViewModels" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <UserControl.Resources> <ViewModels:PropertyFinderViewModel x:Key="PropertyFinderViewModel"></ViewModels:PropertyFinderViewModel> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource PropertyFinderViewModel}"> <Intersoft:FieldLabel Header="Select Size (in sq ft.): " HeaderWidth="150" VerticalAlignment="Top"> <Intersoft:UXSliderBar Width="300" TickPlacement="BottomRight" HandlesVisibility="True" Minimum="500" Maximum="1000" LargeChange="100" SmallChange="10" Value="{Binding PropertyFinder.PropertySize, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"/> </Intersoft:FieldLabel> </Grid> </UserControl> |
The following figure shows that the error message is displayed when the value of UXSliderBar is smaller than 600 sq ft.