Intersoft ClientUI 8 > ClientUI Fundamentals > Data Binding Overview > Data Binding How-to Topics > How-to: Bind to an Enumeration |
This example shows how to get data from an enumeration type and bind it to UXListBox.
Enumeration type in Silverlight does not have GetValues method therefore you need a different way to get the values from an enumeration type.
The following sample code shows how to get the data from an enumeration type using Intersoft DataProvider.
View Model |
Copy Code
|
---|---|
using System.Collections.Generic; using System.ComponentModel; using System.Windows; using Intersoft.Client.Framework; namespace ClientUI.Samples.ViewModels { public class MainPageViewModel : INotifyPropertyChanged { public MainPageViewModel() { this.VisibilityEnum = DataProvider.GetData(typeof(Visibility)); } private List<object> _visibilityEnum; public List<object> VisibilityEnum { get { return this._visibilityEnum; } set { if (this._visibilityEnum != value) { this._visibilityEnum = value; this.OnPropertyChanged("VisibilityEnum"); } } } protected void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; } } |
View |
Copy Code
|
---|---|
<Grid x:Name="LayoutRoot" Background="White"> <Grid.DataContext> <vm:MainPageViewModel/> </Grid.DataContext> <Intersoft:UXListBox ItemsSource="{Binding VisibilityEnum}" Width="100" VerticalAlignment="Center" HorizontalAlignment="Center"> </Intersoft:UXListBox> </Grid> |