protected override Value <string> ConvertTo(ConverterData <long> input) { var format = FileSizeFormat.BinaryUsingSI; Try.Invoke(() => format = (FileSizeFormat)Enum.Parse(typeof(FileSizeFormat), input.Parameter.ToString())); return(input.ActualValue.FileSize(format)); }
protected override Value <string> ConvertTo(ConverterData <object> input) { var path = input.ActualValue.ToString(); if (path == StoragePath.Root) { return(StoragePath.RootName); } if (path.EndsWith(@":\")) { foreach (var i in Computer.Drives) { if (path.Equals(i.Name)) { return($"{i.VolumeLabel} ({i.Name.Replace(@"\", string.Empty)})"); } } return(path); } return(Folder.Long.Exists(path) || input.ActualParameter == 1 ? Path.GetFileName(path) : input.ActualParameter == 0 ? Path.GetFileNameWithoutExtension(path) : throw input.InvalidParameter); }
protected override Value <string> ConvertTo(ConverterData <string> input) { string result = null; return(!Try.Invoke(() => result = Path.GetExtension(input.ActualValue)) ? (Value <string>)Nothing.Do : input.ActualParameter == 0 ? result.Replace(".", string.Empty) : input.ActualParameter == 1 ? result : throw input.InvalidParameter); }
protected override Value <Visibility> ConvertTo(ConverterData <object> input) { if (input.Parameter is Type i) { return(input.ActualValue.GetType().IsSubclassOf(i).Visibility()); } return(Nothing.Do); }
protected override Value <object> ConvertBack(ConverterData <bool> input) { if (!input.ActualValue || input.Parameter == null) { return(Nothing.Do); } return(input.Parameter); }
protected override Value <string> ConvertTo(ConverterData <object> input) { if (input.ActualValue is string || input.ActualValue is Enum) { var i = input.ActualValue.ToString(); Try.Invoke(() => i = i.Substring(0, input.ActualParameter == 0 ? i.Length : input.ActualParameter)); return(i); } return(default);
protected override Value <object> ConvertTo(ConverterData <object> input) { if (input.Value == null || (input.Value is string i && i.Empty())) { return(Nothing.Do); } return(input.Value); }
protected override Value <string> ConvertTo(ConverterData <object> input) { if (input.ActualValue is DateTime a) { return(a.Relative()); } return(input.ActualValue.As <DateTime?>()?.Relative() ?? (Value <string>)Nothing.Do); }
protected override Value <string> ConvertTo(ConverterData <string> input) { if (!input.ActualValue.Empty()) { return(input.ActualValue.Substring(0, 1)); } return(Nothing.Do); }
protected override Value <int> ConvertTo(ConverterData <FrameworkElement> input) { var item = input.ActualValue; var itemsControl = ItemsControl.ItemsControlFromItemContainer(item); var index = itemsControl?.ItemContainerGenerator.IndexFromContainer(item) ?? 0; return(input.ActualParameter + index); }
protected override Value <bool> ConvertTo(ConverterData <object> input) { if (input.Parameter is Type i) { return(input.ActualValue.GetType().IsSubclassOf(i) || input.ActualValue.GetType().Equals(i)); } return(false); }
protected override Value <double> ConvertTo(ConverterData <long> input) { if (input.Value == null) { return(0); } double.TryParse(input.ActualValue.ToString(), out double result); return((result / 1024d / 1024d).Round(3)); }
protected override Value <ImageSource> ConvertTo(ConverterData <Uri> input) { var i = new BitmapImage(); i.BeginInit(); i.UriSource = input.ActualValue; i.EndInit(); return(i as ImageSource); }
protected override Value <PathCollection> ConvertTo(ConverterData <string> input) { if (!input.ActualValue.NullOrEmpty()) { var path = StoragePath.GetLastExtension(input.ActualValue).NullOrEmpty() ? input.ActualValue : Path.GetDirectoryName(input.ActualValue); var result = new PathCollection(new Filter(ItemType.File)); result.Refresh(path); return(result); } return(Nothing.Do); }
protected override Value <string> ConvertTo(ConverterData <TimeSpan> input) { var result = DateTime.Today.AddSeconds(input.ActualValue.TotalSeconds); if (input.Parameter is string format) { return(result.ToString(format)); } return($"{result}"); }
protected override Value <System.Windows.Controls.SelectionMode> ConvertTo(ConverterData <SelectionMode> input) { switch (input.ActualValue) { case SelectionMode.Multiple: return(System.Windows.Controls.SelectionMode.Extended); case SelectionMode.Single: case SelectionMode.SingleOrNone: return(System.Windows.Controls.SelectionMode.Single); } throw new NotSupportedException(); }
protected override Value <object> ConvertBack(ConverterData <object> input) { if (input.Value is Visibility visibility) { var result = ((Visibility)input.Value).Boolean(); return(input.ActualParameter == 0 ? result : input.ActualParameter == 1 ? !result : throw input.InvalidParameter); } return(ConvertTo(input)); }
protected override Value <object> ConvertTo(ConverterData <object> input) { if (input.Value is bool || input.Value is bool? || input.Value is Handle) { var i = input.Value is bool?(bool)input.Value : input.Value is bool? ?((bool?)input.Value).Value : input.Value is Handle ? (bool)(Handle)input.Value : throw new NotSupportedException(); var result = i.Visibility(input.Parameter is Visibility ? (Visibility)input.Parameter : Visibility.Collapsed); return(input.ActualParameter == 0 ? result : input.ActualParameter == 1 ? result.Invert() : throw input.InvalidParameter); } return(ConvertBack(input)); }
protected override Value <string> ConvertTo(ConverterData <double> input) { long result = 0; if (input.Value is double a) { result = a.Int64(); } if (input.Value is string b) { result = b.Int64(); } return($"{result.FileSize(FileSizeFormat.BinaryUsingSI)}/s"); }
protected override Value <StringCollection> ConvertTo(ConverterData <object> input) { var result = new StringCollection(); if (input.ActualValue is IEnumerable a) { a.ForEach(i => result.Add(i.ToString())); } if (input.ActualValue is IList b) { b.ForEach(i => result.Add(i.ToString())); } return(result); }
protected override Value <string> ConvertTo(ConverterData <object> input) { string result = null; if (input.ActualValue is Enum a) { result = a.GetAttribute <DisplayNameAttribute>()?.DisplayName ?? a.GetAttribute <System.ComponentModel.DisplayNameAttribute>()?.DisplayName; return(result ?? a.ToString().SplitCamel()); } if (input.ActualValue is object b) { var type = b.GetType(); result = type.GetAttribute <DisplayNameAttribute>()?.DisplayName ?? type.GetAttribute <System.ComponentModel.DisplayNameAttribute>()?.DisplayName; return(result ?? type.Name); } return(Nothing.Do); }
protected override Value <string> ConvertTo(ConverterData <object> input) { TimeSpan result = TimeSpan.Zero; if (input.ActualValue is int a) { result = TimeSpan.FromSeconds(a); } else if (input.ActualValue is string b) { result = TimeSpan.FromSeconds(b.Int32()); } else { var now = DateTime.Now; if (input.ActualValue is DateTime c) { result = c > now ? c - now : now - c; } if (input.ActualValue is DateTime?) { var d = input.ActualValue as DateTime?; if (d == null) { return(string.Empty); } result = d.Value > now ? d.Value - now : now - d.Value; } } return(result.ShortTime(input.ActualParameter == 1)); }
protected override Value <FontFamily> ConvertTo(ConverterData <string> input) { if (input.ActualValue == null) { return(default);
protected override Value <Thickness> ConvertBack(ConverterData <Thickness> input) => input.ActualValue.Invert();
protected override Value <string> ConvertBack(ConverterData <int> input) => Nothing.Do;
protected override Value <int> ConvertTo(ConverterData <string> input) => input.ActualValue.Length;
protected override Value <FrameworkElement> ConvertBack(ConverterData <int> input) => Nothing.Do;
protected override Value <DataGridLength> ConvertBack(ConverterData <GridLength> input) => new DataGridLength();
protected override Value <GridLength> ConvertTo(ConverterData <DataGridLength> input) => new GridLength();
protected override Value <ControlLength> ConvertBack(ConverterData <GridLength> input) => (ControlLength)input.ActualValue;