Silverlight数据绑定转换示例
2012-02-12 00:19
363 查看
<Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <local:ColorConverter x:Key="ColorConverter"></local:ColorConverter> </Grid.Resources> <Ellipse Width="300" Height="200" Fill="{Binding Status,Converter={StaticResource ColorConverter},Mode=TwoWay}"></Ellipse> </Grid>
public enum TrafficStatus { Stop,Ready,Go } public class TrafficLight : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public TrafficStatus Status { get { return status; } set { status = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("status")); } } } private TrafficStatus status; } public class ColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { TrafficStatus status = (TrafficStatus)value; SolidColorBrush brush = new SolidColorBrush(Colors.Red); switch (status) { case TrafficStatus.Stop: break; case TrafficStatus.Ready: brush = new SolidColorBrush(Colors.Orange); break; case TrafficStatus.Go: brush = new SolidColorBrush(Colors.Green); break; default: break; } return brush; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { TrafficLight traffic = new TrafficLight() { Status = TrafficStatus.Stop }; this.DataContext = traffic; }Silverlight数据绑定转换.rar
相关文章推荐
- Silverlight数据绑定转换示例
- Silverlight数据绑定转换示例
- WPF and Silverlight 学习笔记(二十一):数据绑定值的自定义转换
- silverlight 数据绑定简单示例(markup extension)
- Silverlight学习之【最简单数据绑定示例】
- silverlight 数据绑定简单示例(creating dynamic bindings)
- WPF and Silverlight 学习笔记(二十一):数据绑定值的自定义转换
- SpringMVC数据绑定全面示例(复杂对象,数组等)
- Silverlight数据绑定简单例子
- ListView 数据绑定、数据汇总及自定义排序示例
- Angular2学习笔记之数据绑定的示例代码
- spring MVC 数据的绑定 验证 转换---属性编辑器
- 具有强大构建强大的Word报表,支持XAML数据绑定,文档格式转换,导出为PDF等功能的控件TX Text Control .NET for WPF介绍
- 6.校验,数据绑定和类型转换(6.1 - 6.3)
- silverlight 绑定数据输出格式的设定
- Silverlight 之数据绑定(简单例子)
- 一步一步学Silverlight :数据绑定
- 稳扎稳打Silverlight(51) - 4.0绑定之数据验证IDataErrorInfo, INotifyDataErrorInfo
- 稳扎稳打Silverlight(51) - 4.0绑定之数据验证IDataErrorInfo, INotifyDataErrorInfo
- 稳扎稳打Silverlight(51) - 4.0绑定之数据验证IDataErrorInfo, INotifyDataErrorInfo