Created
July 4, 2019 02:57
-
-
Save wenhelinlu/b81398102a7b00ee9f88f2632531d890 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Globalization; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Windows.Data; | |
| using System.Windows.Media.Imaging; | |
| namespace HMT.Controls | |
| { | |
| public class MultiInt2VisiblityConverter : IMultiValueConverter | |
| { | |
| public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) | |
| { | |
| //邮件类型 | |
| int mailType = (int)values[0]; | |
| //明细条目数量 | |
| int detailCount = (int)values[1]; | |
| //明细数量大于0,则设为1,表示有明细,为了方便switch的判断 | |
| if(detailCount > 0) | |
| { | |
| detailCount = 1; | |
| } | |
| //默认图标 | |
| string iconPath = ""; | |
| string v = $"{mailType}{detailCount}"; | |
| switch (v) | |
| { | |
| case "00": | |
| iconPath = "/HMT.Resources;component/Resources/inbox.png"; | |
| break; | |
| case "01": | |
| iconPath = "/HMT.Resources;component/Resources/inbox_top.png"; | |
| break; | |
| case "10": | |
| iconPath = "/HMT.Resources;component/Resources/sent.png"; | |
| break; | |
| case "11": | |
| iconPath = "/HMT.Resources;component/Resources/sent_top.png"; | |
| break; | |
| } | |
| //注意:使用MultiBinding的方式来给Image Source属性赋值,需要转换成BitmapImage对象,和单个Binding的方式不同, | |
| //而且Uri的参数中需要加pack://application:,,,前缀 | |
| return new BitmapImage(new Uri($"pack://application:,,,{iconPath}")); | |
| } | |
| public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment