其他分享
首页 > 其他分享> > WPF 转换器的使用(Converter)

WPF 转换器的使用(Converter)

作者:互联网

<UserControl.Resources>
        <converters:GPSValueConverter x:Key="gPSname">
        </converters:GPSValueConverter>
 </UserControl.Resources>

ListView中改变某列内容显示

 <GridViewColumn Header="经度" Width="72" DisplayMemberBinding="{Binding Longitude,Converter={StaticResource gPSname}}" HeaderContainerStyle="{StaticResource st}"/>
                                    <GridViewColumn Header="纬度" Width="80" DisplayMemberBinding="{Binding Latitude,Converter={StaticResource gPSname}}" HeaderContainerStyle="{StaticResource st}"/>
public class GPSValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string s = value.ToString();
            return s.Substring(0,6);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

标签:Converter,object,value,culture,转换器,WPF,Type,public,CultureInfo
来源: https://blog.csdn.net/weixin_42327816/article/details/120221196