예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        protected override Value <Visibility> ConvertTo(ConverterData <object> input)
        {
            if (input.Parameter is Type i)
            {
                return(input.ActualValue.GetType().IsSubclassOf(i).Visibility());
            }

            return(Nothing.Do);
        }
예제 #5
0
        protected override Value <object> ConvertBack(ConverterData <bool> input)
        {
            if (!input.ActualValue || input.Parameter == null)
            {
                return(Nothing.Do);
            }

            return(input.Parameter);
        }
예제 #6
0
 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);
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        protected override Value <string> ConvertTo(ConverterData <string> input)
        {
            if (!input.ActualValue.Empty())
            {
                return(input.ActualValue.Substring(0, 1));
            }

            return(Nothing.Do);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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));
        }
예제 #13
0
        protected override Value <ImageSource> ConvertTo(ConverterData <Uri> input)
        {
            var i = new BitmapImage();

            i.BeginInit();
            i.UriSource = input.ActualValue;
            i.EndInit();

            return(i as ImageSource);
        }
예제 #14
0
 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);
 }
예제 #15
0
        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}");
        }
예제 #16
0
        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();
        }
예제 #17
0
        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));
        }
예제 #18
0
        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));
        }
예제 #19
0
        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");
        }
예제 #20
0
        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);
        }
예제 #21
0
        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);
        }
예제 #22
0
        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));
        }
예제 #23
0
 protected override Value <FontFamily> ConvertTo(ConverterData <string> input)
 {
     if (input.ActualValue == null)
     {
         return(default);
예제 #24
0
 protected override Value <Thickness> ConvertBack(ConverterData <Thickness> input) => input.ActualValue.Invert();
예제 #25
0
 protected override Value <string> ConvertBack(ConverterData <int> input) => Nothing.Do;
예제 #26
0
 protected override Value <int> ConvertTo(ConverterData <string> input) => input.ActualValue.Length;
예제 #27
0
 protected override Value <FrameworkElement> ConvertBack(ConverterData <int> input) => Nothing.Do;
예제 #28
0
 protected override Value <DataGridLength> ConvertBack(ConverterData <GridLength> input) => new DataGridLength();
예제 #29
0
 protected override Value <GridLength> ConvertTo(ConverterData <DataGridLength> input) => new GridLength();
예제 #30
0
 protected override Value <ControlLength> ConvertBack(ConverterData <GridLength> input) => (ControlLength)input.ActualValue;