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}'}"
  • 相关阅读:
    oracle11g expdp/impdp数据库
    SqlServer触发器
    tomcat8.5.20配置https
    oracle常用函数积累
    Eclipse 搭建tomcat+动态项目完整版
    Windows7下ftp服务器
    Orcle定时生成表数据作业
    Oracle将一列值逗号拼接wm_concat函数
    Oracle表空间 ORA-01653:
    node+mongodb+ionic+cordova
  • 原文地址:https://www.cnblogs.com/otomii/p/2035135.html
Copyright © 2011-2022 走看看