Converter
public class ImgPathConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
string CommadnFolderPath = System.Environment.CurrentDirectory;
string FilePath = System.IO.Path.Combine(CommadnFolderPath, @"Picture\Server\GroupPage\");
string ImagePath;
switch((SyncModel.PlatformType)value)
{
case SyncModel.PlatformType.DoNetClient :
ImagePath = FilePath + "server_pc.png";
break;
case SyncModel.PlatformType.DoNetClientAIO:
ImagePath = FilePath + "server_aio.png";
break;
case SyncModel.PlatformType.DoNetClientNB:
ImagePath = FilePath + "server_nb.png";
break;
case SyncModel.PlatformType.DoNetClientTable:
ImagePath = FilePath + "server_tablet.png";
break;
case SyncModel.PlatformType.DoNetClientMSIAIO:
ImagePath = FilePath + "server_aio_msi.png";
break;
case SyncModel.PlatformType.DoNetClientMSINB:
ImagePath = FilePath + "server_nb_msi.png";
break;
case SyncModel.PlatformType.DoNetClientMSITable:
ImagePath = FilePath + "server_tablet_msi.png";
break;
default :
ImagePath = FilePath + "server_pc.png";
break;
} Uri uri = new Uri(ImagePath, UriKind.Absolute); //Uri uri = new Uri((value as string),UriKind.Relative);
ImageBrush imgBru = new ImageBrush(); BitmapImage bImg = new BitmapImage();
bImg.BeginInit();
bImg.CacheOption = BitmapCacheOption.OnLoad;
bImg.UriSource = uri;
bImg.EndInit(); imgBru.ImageSource = bImg;
imgBru.Stretch = Stretch.Fill;
bImg.Freeze();
return imgBru;
// return (isVisible ? Visibility.Visible : Visibility.Hidden);
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
return value;
// throw new InvalidOperationException("Not yet support this function!");
}
}
public class BoolVisibleConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isVisible;
if (value == null || !(value is bool))
{
isVisible = false;
}
else
{
isVisible = (bool)value;
}
return (isVisible ? Visibility.Visible : Visibility.Hidden);
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new InvalidOperationException("Not yet support this function!");
}
}
public class DateTimeToStringConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
DateTime d = (DateTime)value;
if (DateTime.Equals(d, DateTime.MinValue))
return string.Empty;
else
return d;
}
public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture)
{
throw new InvalidOperationException("Not yet support this function!");
}
}
Converter的更多相关文章
- 解决springmvc报No converter found for return value of type: class java.util.ArrayList问题
一.背景 最近闲来无事,想自己搭建一套Spring+SpringMVC+Mybatis+Mysql的环境(搭建步骤会在以后博客中给出),结果运行程序时,适用@ResponseBody注解进行返回Lis ...
- spring类型自动转换——@InitBinder和Converter
spring有2种类型转换器,一种是propertyEditor,一种是Converter.虽然都是类型转换,但是还是有细微差别. 所以这里以一个例子的形式来分析一下这2种类型转换的使用场景和差别. ...
- 破解Java to C# Converter
起因 最近在对接一个第三方平台.该平台只提供了Java版本的SDK,C#版本的还处于敬请期待状态.由于C#可以复用绝大部分代码,便考虑找一个Java到C#的转换器,在试用了几个软件之后,发现还是Jav ...
- wpf converter converterparameter 绑定多参数
1. converterparameter不是依赖属性,所以不能用binding. 2. 可以把converter 的接口 IValueConverter改为 IMultiValueConverter ...
- 新版Retrofit 2可运行例子(解决Could not locate ResponseBody converter for问题)
Retrofit这东西我就不多做解释了,反正最近应用很广,基本都快和OkHttp一起成为安卓的事实网络访问标准框架了. 这么好的一个东西,官网文档实在是不算太好,说的不太清晰.按官网的经常会有“Cou ...
- Converter转换器使用
package com.xu.javabean; import java.lang.reflect.InvocationTargetException; import java.util.Date; ...
- Ultra Video Splitter & Converter
1. Video Splitter http://www.aone-soft.com/splitter.htm Ultra Video Splitter 是一款视频分割工具.可将一个巨大的AVI/Di ...
- Windows Server 2008 Workstation Converter优化设置
http://www.win2008workstation.com/windows-server-2008-workstation-converter/ If you don’t want to co ...
- 电量显示Binding Converter MVVM
用一个ProcessBar显示电量,低于20%时候,ForeGround为红色,否则为绿色, 页面使用了MVVM绑定到了ViewModel, ProcessBar XAML为 <Progress ...
- 自定义类型转换器converter
作用:目前将日期转换成string,将string转换成我想要的类型 0509课件里讲 一.数据类型转换在web应用程序中,数据存在两个方向上的转换:1.当提交表单时 表单数据以字符串的形式提交 ...
随机推荐
- C#验证手机号
using System.Text.RegularExpressions; private bool IsMobile(string phoneNo) { return Regex.IsMatch(p ...
- tplink-如何远程WEB管理路由器?
http://service.tp-link.com.cn/detail_article_185.html 如何远程WEB管理路由器? 新版tplink怎么远程Web管理? https://www.1 ...
- [Angular] Some performance tips
The talk from here. 1. The lifecycle in Angular component: constructor vs ngOnInit: Constructor: onl ...
- HDU 3215 The first place of 2^n (数论-水题)
The first place of 2^n Problem Description LMY and YY are mathematics and number theory lovers. They ...
- color2gray 的实现
无论是 rgb 还是 yuv 等三通道的颜色空间中的像素点,将其转换为单通道(pixel_depth=255.)中的像素,一般情况下都是采用的对原始颜色空间的 3 通道的像素点线性组合而得到单通道的像 ...
- XML 标准诞生 20 周年:这个世界,它无处不在
可扩展标记语言(XML)于 1998 年 2 月 10 日成为 W3C 的推荐标准.昨天,2018 年 2 月 10 日恰好是 W3C 推出的 XML 标准发布 20 周年纪念日.可点此查看原始的新闻 ...
- SecondaryNameNode 的作用
Secondary NameNode:它究竟有什么作用? 尽量不要将 secondarynamede 和 namenode 放在同一台机器上. 1. NameNode NameNode 主要是用来保存 ...
- Java堆/栈/常量池以及String的详细详解(转)------经典易懂系统
一:在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register). 这是最快的存储区,因为它位于不同于其他存储区的地方——处理器内部.但是寄存器的数量极其有限,所以寄存器由编译器根据 ...
- win32命令行小程序获取指定文件夹或者目录下面的所有文件大小,文件数量,目录数量
#include <Windows.h> #include <stdio.h> #include <tchar.h> LARGE_INTEGER lgA ...
- Spring异步方法注解 @Async
@Async 0. 介绍 在Spring 3.x之后,通过内置@Async标明异步方法,可以简化异步开发流程. @Async既可提供无返回值的调用,也可提供有返回值的调用,下文将分别介绍两种使用方式. ...