public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { // Check input parameter types if (values == null) { return(Binding.DoNothing); } if (values.Length != 2) { return(Binding.DoNothing); } TypeOfSolutionItem type = TypeOfSolutionItem.Unknown; bool typeIsAssigned = false; ItemExisits state = ItemExisits.Unknown; bool stateIsAssigned = false; for (int i = 0; i < values.Length; i++) { if (values[i] is TypeOfSolutionItem) { type = (TypeOfSolutionItem)values[i]; typeIsAssigned = true; } else { if (values[i] is ItemExisits) { state = (ItemExisits)values[i]; stateIsAssigned = true; } } } if (typeIsAssigned == false) { throw new ArgumentException(string.Format("Expected argument: '{0}' was not supplied.", type.GetType().ToString())); } if (stateIsAssigned == false) { throw new ArgumentException(string.Format("Expected argument: '{0}' was not supplied.", state.GetType().ToString())); } if (targetType != typeof(System.Windows.Media.ImageSource)) { throw new ArgumentException("Invalid return type. Expected return type: System.Windows.Media.ImageSource"); } string resourceUri = string.Empty; string stateExtension = string.Empty; switch (state) { case ItemExisits.Unknown: stateExtension = "Unknown"; break; case ItemExisits.DoesExist: stateExtension = string.Empty; break; case ItemExisits.DoesNotExist: stateExtension = "Problem"; break; default: throw new NotImplementedException(state.ToString()); } string typeURL = string.Empty; switch (type) { case TypeOfSolutionItem.Root: typeURL = "Icon_Solution"; break; case TypeOfSolutionItem.Project: typeURL = "Icon_Project"; break; case TypeOfSolutionItem.File: typeURL = "Icon_Documents"; break; case TypeOfSolutionItem.Unknown: default: throw new NotImplementedException(state.ToString()); } string resourceKey = string.Format("{0}{1}", typeURL, (string.IsNullOrEmpty(stateExtension) ? string.Empty : "_" + stateExtension)); return(Application.Current.FindResource(resourceKey)); }
/// <summary> /// Set a property to determine whether a file is actually exiosting or not. /// </summary> public void SetExists(ItemExisits newValue) { Exists = newValue; }