Esempio n. 1
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(new MemberSelector
     {
         MemberName = (string)value,
     });
 }
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return new MemberSelector
     {
         MemberName = (string)value,
     };
 }
Esempio n. 3
0
 public object ConvertTo(
     IXamlTypeConverterContext context,
     CultureInfo culture,
     object value,
     Type destinationType)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var colorString = (string)value;

            var color = DecodeColor(colorString);

            return new SolidColorBrush(color);
        }
Esempio n. 5
0
 public object ConvertTo(
     IXamlTypeConverterContext context,
     CultureInfo culture,
     object value,
     Type destinationType)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                return(value);
            }

            return(null);
        }
Esempio n. 7
0
        public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
        {
            if (destinationType == typeof(string) || destinationType == typeof(int))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
        {
            if (destinationType == typeof(string) || destinationType == typeof(int))
            {
                return true;
            }

            return false;
        }
Esempio n. 9
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                return value;
            }

            return null;
        }
Esempio n. 10
0
        public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
        {
            if ((string) value == "Auto")
            {
                return new GridLength(0, GridUnitType.Auto);
            }

            return new GridLength(1, GridUnitType.Star);
        }
Esempio n. 11
0
        public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
        {
            if (sourceType == typeof(string))
            {
                return true;
            }

            return false;
        }
Esempio n. 12
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var s = value as string;
            if (s != null)
            {
                return ConvertFromString(s);
            }

            return null;
        }
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     string strValue = (string)value;
     string[] pointStrs = strValue.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
     var result = new List<Point>(pointStrs.Length);
     foreach (var pointStr in pointStrs)
     {
         result.Add(Point.Parse(pointStr, culture));
     }
     return result;
 }
Esempio n. 14
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var valueStr = (string)value;
            if (!valueStr.Contains(":"))
            {
                // shorthand seconds format (ie. "0.25")
                var secs = double.Parse(valueStr);
                return TimeSpan.FromSeconds(secs);
            }

            return TimeSpan.Parse(valueStr);
        }
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var s = (string)value;

            string typeName;
            string propertyName;
            Type type;

            ParseProperty(s, out typeName, out propertyName);

            if (typeName == null)
            {
                var styleType = context.TypeRepository.GetXamlType(typeof(Style));
                var style = (Style)context.TopDownValueContext.GetLastInstance(styleType);
                type = style.Selector.TargetType;

                if (type == null)
                {
                    throw new XamlParseException(
                        "Could not determine the target type. Please fully qualify the property name.");
                }
            }
            else
            {
                type = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType;

                if (type == null)
                {
                    throw new XamlParseException($"Could not find type '{typeName}'.");
                }
            }

            // Ensure the type's static ctor has been run.
            RuntimeHelpers.RunClassConstructor(type.TypeHandle);

            // First look for non-attached property on the type and then look for an attached property.
            var property = PerspexPropertyRegistry.Instance.FindRegistered(type, s);
            
            if (property == null)
            {
                property = PerspexPropertyRegistry.Instance.GetAttached(type)
                    .FirstOrDefault(x => x.Name == propertyName);
            }

            if (property == null)
            {
                throw new XamlParseException(
                    $"Could not find PerspexProperty '{type.Name}.{propertyName}'.");
            }

            return property;
        }
Esempio n. 16
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var s = (string)value;

            string typeName;
            string propertyName;
            Type   type;

            ParseProperty(s, out typeName, out propertyName);

            if (typeName == null)
            {
                var styleType = context.TypeRepository.GetXamlType(typeof(Style));
                var style     = (Style)context.TopDownValueContext.GetLastInstance(styleType);
                type = style.Selector.TargetType;

                if (type == null)
                {
                    throw new XamlParseException(
                              "Could not determine the target type. Please fully qualify the property name.");
                }
            }
            else
            {
                type = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType;

                if (type == null)
                {
                    throw new XamlParseException($"Could not find type '{typeName}'.");
                }
            }

            // Ensure the type's static ctor has been run.
            RuntimeHelpers.RunClassConstructor(type.TypeHandle);

            // First look for non-attached property on the type and then look for an attached property.
            var property = PerspexPropertyRegistry.Instance.FindRegistered(type, s);

            if (property == null)
            {
                property = PerspexPropertyRegistry.Instance.GetAttached(type)
                           .FirstOrDefault(x => x.Name == propertyName);
            }

            if (property == null)
            {
                throw new XamlParseException(
                          $"Could not find PerspexProperty '{type.Name}.{propertyName}'.");
            }

            return(property);
        }
Esempio n. 17
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var valueStr = (string)value;

            if (!valueStr.Contains(":"))
            {
                // shorthand seconds format (ie. "0.25")
                var secs = double.Parse(valueStr, CultureInfo.InvariantCulture);
                return(TimeSpan.FromSeconds(secs));
            }

            return(TimeSpan.Parse(valueStr));
        }
Esempio n. 18
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var str = value as string;

            if (str != null)
            {
                if (string.Equals(str, "Auto"))
                {
                    return new GridLength(0, GridUnitType.Auto);
                }
            }

            return new GridLength(1, GridUnitType.Star);
        }
Esempio n. 19
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var uri = new Uri((string)value, UriKind.RelativeOrAbsolute);
            var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file";

            switch (scheme)
            {
                case "file":
                    return new Bitmap((string)value);
                default:
                    var assets = PerspexLocator.Current.GetService<IAssetLoader>();
                    return new Bitmap(assets.Open(uri));
            }
        }
Esempio n. 20
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var uri    = new Uri((string)value, UriKind.RelativeOrAbsolute);
            var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file";

            switch (scheme)
            {
            case "file":
                return(new Bitmap((string)value));

            default:
                var assets = PerspexLocator.Current.GetService <IAssetLoader>();
                return(new Bitmap(assets.Open(uri)));
            }
        }
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var s       = (string)value;
            var lastDot = s.LastIndexOf('.');

            if (lastDot == -1)
            {
                throw new NotSupportedException("PerspexProperties must currently be fully qualified.");
            }

            var typeName     = s.Substring(0, lastDot);
            var propertyName = s.Substring(lastDot + 1);
            var type         = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType;
            var styleType    = context.TypeRepository.GetXamlType(typeof(Style));

            // ATTN: SuperJMN
            //var style = ((XamlTypeConverterContext)context).TopDownValueContext.GetLastInstance(styleType);

            if (type == null)
            {
                throw new XamlParseException($"Could not find type '{typeName}'.");
            }

            // First look for non-attached property on the type and then look for an attached property.
            var property = PerspexObject.GetRegisteredProperties(type)
                           .FirstOrDefault(x => x.Name == propertyName);

            if (property == null)
            {
                property = PerspexObject.GetAttachedProperties(type)
                           .FirstOrDefault(x => x.Name == propertyName);
            }

            if (property == null)
            {
                throw new XamlParseException(
                          $"Could not find PerspexProperty '{typeName}'.{propertyName}.");
            }

            return(property);
        }
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var s = (string)value;
            var lastDot = s.LastIndexOf('.');

            if (lastDot == -1)
            {
                throw new NotSupportedException("PerspexProperties must currently be fully qualified.");
            }

            var typeName = s.Substring(0, lastDot);
            var propertyName = s.Substring(lastDot + 1);
            var type = context.TypeRepository.GetByQualifiedName(typeName)?.UnderlyingType;
            var styleType = context.TypeRepository.GetXamlType(typeof(Style));

            // ATTN: SuperJMN
            //var style = ((XamlTypeConverterContext)context).TopDownValueContext.GetLastInstance(styleType);

            if (type == null)
            {
                throw new XamlParseException($"Could not find type '{typeName}'.");
            }

            // First look for non-attached property on the type and then look for an attached property.
            var property = PerspexObject.GetRegisteredProperties(type)
                .FirstOrDefault(x => x.Name == propertyName);

            if (property == null)
            {
                property = PerspexObject.GetAttachedProperties(type)
                    .FirstOrDefault(x => x.Name == propertyName);
            }

            if (property == null)
            {
                throw new XamlParseException(
                    $"Could not find PerspexProperty '{typeName}'.{propertyName}.");
            }

            return property;
        }
Esempio n. 23
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var result = new PerspexList <T>();
            var values = ((string)value).Split(',');

            foreach (var s in values)
            {
                object v;

                if (TypeUtilities.TryConvert(typeof(T), s, culture, out v))
                {
                    result.Add((T)v);
                }
                else
                {
                    throw new InvalidCastException($"Could not convert '{s}' to {typeof(T)}.");
                }
            }

            return(result);
        }
Esempio n. 24
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var str = value as string;

            if (value is int)
            {
                return(Convert.ToInt32(value, CultureInfo.InvariantCulture));
            }
            if (value is long)
            {
                return(Convert.ToInt32(value, CultureInfo.InvariantCulture));
            }
            else if (str != null)
            {
                long v;
                if (long.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out v))
                {
                    return((int)v);
                }
            }

            throw new InvalidOperationException();
        }
Esempio n. 25
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var str = value as string;

            if (value is int)
            {
                return Convert.ToInt32(value, CultureInfo.InvariantCulture);
            }
            if (value is long)
            {
                return Convert.ToInt32(value, CultureInfo.InvariantCulture);
            }
            else if (str != null)
            {
                long v;
                if (long.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out v))
                {
                    return (int)v;
                }
            }

            throw new InvalidOperationException();
        }
Esempio n. 26
0
        public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value == null)
            {
                return(null);
            }

            if (destinationType == typeof(int))
            {
                var str = value as string;
                if (str != null)
                {
                    int n;
                    if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out n))
                    {
                        return(n);
                    }
                    return(null);
                }
            }

            if (destinationType == typeof(double))
            {
                var str = value as string;
                if (str != null)
                {
                    double n;
                    if (double.TryParse(str, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out n))
                    {
                        return(n);
                    }
                    return(null);
                }
            }

            return(value.ToString());
        }
Esempio n. 27
0
        public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value == null)
            {
                return null;
            }

            if (destinationType == typeof(int))
            {
                var str = value as string;
                if (str != null)
                {
                    int n;
                    if (int.TryParse(str, out n))
                    {
                        return n;
                    }
                    return null;
                }
            }

            if (destinationType == typeof(double))
            {
                var str = value as string;
                if (str != null)
                {
                    double n;
                    if (double.TryParse(str, out n))
                    {
                        return n;
                    }
                    return null;
                }
            }

            return value.ToString();
        }
Esempio n. 28
0
        public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value == null)
            {
                return null;
            }

            if (destinationType == typeof(int))
            {
                var str = value as string;
                if (str != null)
                {
                    int n;
                    if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out n))
                    {
                        return n;
                    }
                    return null;
                }
            }

            if (destinationType == typeof(double))
            {
                var str = value as string;
                if (str != null)
                {
                    double n;
                    if (double.TryParse(str, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out n))
                    {
                        return n;
                    }
                    return null;
                }
            }

            return value.ToString();
        }
Esempio n. 29
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(RelativeRect.Parse((string)value, culture));
 }
Esempio n. 30
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return GridLength.Parse((string)value);
 }
Esempio n. 31
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return StreamGeometry.Parse((string)value);
 }
Esempio n. 32
0
 public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
 {
     return(value.ToString());
 }
Esempio n. 33
0
 public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
 {
     return new Bitmap(10, 10);
 }
Esempio n. 34
0
 public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
 {
     return true;
 }
Esempio n. 35
0
 public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
 {
     return(converter.ConvertTo(null, culture, value, destinationType));
 }
Esempio n. 36
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(new ColumnDefinitions((string)value));
 }
Esempio n. 37
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(double.Parse((string)value, CultureInfo.InvariantCulture));
 }
Esempio n. 38
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     var cursor = (StandardCursorType)Enum.Parse(typeof (StandardCursorType), ((string) value).Trim(), true);
     return new Cursor(cursor);
 }
Esempio n. 39
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var parser = new SelectorParser((t, ns) => context.TypeRepository.GetByPrefix(ns ?? "", t).UnderlyingType);

            return(parser.Parse((string)value));
        }
 public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
 {
     return false;
 }
Esempio n. 41
0
 public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
 {
     return(destinationType == typeof(string));
 }
Esempio n. 42
0
 public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
 {
     throw new NotImplementedException();
 }
Esempio n. 43
0
 public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
 {
     return(converter.CanConvertTo(null, destinationType));
 }
Esempio n. 44
0
 public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
 {
     return(sourceType == typeof(int) || sourceType == typeof(double) || sourceType == typeof(float));
 }
Esempio n. 45
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            ITypeDescriptorContext typeDescriptor = new TypeDescriptorContext();

            return(converter.ConvertFrom(typeDescriptor, culture, value));
        }
Esempio n. 46
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(Thickness.Parse((string)value));
 }
Esempio n. 47
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     var path = (string)value;
     return new Bitmap(path);
 }
Esempio n. 48
0
 public bool CanConvertTo(IXamlTypeConverterContext context, Type destinationType)
 {
     return(false);
 }
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return new RowDefinitions((string)value);
 }
Esempio n. 50
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(StreamGeometry.Parse((string)value));
 }
Esempio n. 51
0
 public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
 {
     return(sourceType == typeof(string));
 }
Esempio n. 52
0
 public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
 {
     return(converter.CanConvertFrom(null, sourceType));
 }
Esempio n. 53
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(new Bitmap((string)value));
 }
Esempio n. 54
0
 public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
 {
     return sourceType == typeof(int) || sourceType == typeof(double) || sourceType == typeof(float);
 }
Esempio n. 55
0
 public object ConvertTo(IXamlTypeConverterContext context, CultureInfo culture, object value, Type destinationType)
 {
     return value.ToString();
 }
Esempio n. 56
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var qualifiedTypeName = value as string;

            return(context.TypeRepository.GetByQualifiedName(qualifiedTypeName).UnderlyingType);
        }
 public bool CanConvertFrom(IXamlTypeConverterContext context, Type sourceType)
 {
     return sourceType == typeof(string);
 }
Esempio n. 58
0
        public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
        {
            var cursor = (StandardCursorType)Enum.Parse(typeof(StandardCursorType), ((string)value).Trim(), true);

            return(new Cursor(cursor));
        }
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return RelativePoint.Parse((string)value, culture);
 }
Esempio n. 60
0
 public object ConvertFrom(IXamlTypeConverterContext context, CultureInfo culture, object value)
 {
     return(new Classes(((string)value).Split(' ')));
 }