1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /* ==============================================================================
- * 功能描述: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
- {
- /// <summary>
- /// ModelCheckConverter
- /// </summary>
- 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<ModeCheckResultBase>;
- 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();
- }
- }
- }
|