/* ============================================================================== * 功能描述:ModelCheckConverter * 创 建 者:Garrett * 创建日期:2019/10/21 16:02:55 * ==============================================================================*/ using System; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media.Imaging; namespace Saga.PlugIn.ModelCheck { /// /// ModelCheckConverter /// class ItemImageVisibleConverter : IValueConverter { public bool IsEqualCollapsed { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var state = (ModelCheckState) value; Visibility visibility = Visibility.Visible; if (IsEqualCollapsed) { visibility = (state.Equals(parameter) ? Visibility.Collapsed : Visibility.Visible); } else { visibility = (!state.Equals(parameter) ? Visibility.Collapsed : Visibility.Visible); } return visibility; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } class ItemImageConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var state = (ModelCheckState)values[0]; BitmapSource image = null; string imageName = null; if(state== ModelCheckState.Progress) imageName = "等待.png"; else { var items = values[1] as ObservableCollection; if (items != null && items.All(t => t.IsRight)) { imageName = "正确.png"; } else { imageName = "错误.png"; } } if (!string.IsNullOrEmpty(imageName)) { Uri uri = new Uri("pack://application:,,,/Saga.PlugIn;component/ModelCheck/Image/" + imageName); image = BitmapFrame.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnDemand); } return image; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }