zoukankan      html  css  js  c++  java
  • WP7备注(31)(Converter)

    基本代码:

    namespace SliderBindings
    {
    public class TruncationConverter : IValueConverter
    {
    public object Convert(object value, Type targetType,
    object parameter, CultureInfo culture)
    {
    if (value is double)
    return Math.Round((double)value);
    return value;
    }
    public object ConvertBack(object value, Type targetType,
    object parameter, CultureInfo culture)
    {
    return value;
    }
    }
    }
    xmlns:local="clr-namespace:SliderBindings"
    
    <phone:PhoneApplicationPage.Resources>
    <local:TruncationConverter x:Key="truncate" />
    </phone:PhoneApplicationPage.Resources>
    
    <TextBlock Name="txtblk"
    Text="{Binding ElementName=slider, Path=Value,
    Converter={StaticResource truncate}}" … />

    带格式化的IConverter:

    public class StringFormatConverter : IValueConverter
    {
    public object Convert(object value, Type targetType,
    object parameter, CultureInfo culture)
    {
    if (targetType == typeof(string) && parameter is string)
    return String.Format(parameter as string, value);
    return value;
    }
    public object ConvertBack(object value, Type targetType,
    object parameter, CultureInfo culture)
    {
    return value;
    }
    }
    Text="{Binding ElementName=slider,
    Path=Value,
    Converter={StaticResource stringFormat},
    ConverterParameter='The slider is {0:F2}'}"
  • 相关阅读:
    iOS8中用UIVisualEffectView实现高斯模糊视图(毛玻璃效果)
    IOS推荐学习网站
    Xcode因为证书问题经常报的那些错
    bug集合令
    html5的标签
    CSS小总结
    JS中的闭包
    前端之路宣告式
    linux安装mysql数据库
    yarn环境搭建
  • 原文地址:https://www.cnblogs.com/otomii/p/2035135.html
Copyright © 2011-2022 走看看