Example #1
0
        public GetMenuWaitInfo()
        {
            Header      = "Just a second...";
            Title       = "We are fetching your personal menu.";
            Reason      = "";
            Description = "";
            var cvn = new ImageSourceConverter();

            if (cvn.CanConvertFrom(Resources.TodaysMenu.GetType()))
            {
                var i = cvn.ConvertFrom(Resources.TodaysMenu);
                Image = (ImageSource)i;
            }
        }
Example #2
0
        public bool SetImageSource(string ImagePath)
        {
            ImageSourceConverter ISC = new ImageSourceConverter();

            if (ISC.CanConvertFrom(ImagePath.GetType()))
            {
                Image.ImageSource = (ImageSource)ISC.ConvertFrom(ImagePath);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value as Uri)?.ToString() == "")
            {
                return(null);
            }

            if (converter.CanConvertFrom(value?.GetType()))
            {
                try {
                    return(converter.ConvertFrom(value));
                }
                catch {}
            }

            return(null);
        }
        static ImageResources()
        {
            var streamResourceInfo = Application.GetResourceStream(new Uri(CallWallIconPath));

            if (streamResourceInfo != null)
            {
                var iconStream = streamResourceInfo.Stream;
                CallWallIcon = new Icon(iconStream);
            }

            var conv = new ImageSourceConverter();

            if (conv.CanConvertFrom(typeof(string)))
            {
                CallWallLogoSource  = (ImageSource)conv.ConvertFrom(CallWallLogoPath);
                CallWallImageSource = (ImageSource)conv.ConvertFrom(CallWallIconPath);
                BirthdayImageSource = (ImageSource)conv.ConvertFrom(BirthdayPath);
            }
        }
Example #5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (value is VirtualFile file)
            {
                return(file.ToImageSource());
            }

            if (Converter.CanConvertFrom(value.GetType()))
            {
                return(Converter.ConvertFrom(value));
            }

            return(null);
        }
Example #6
0
 public override bool CanConvertFrom(Type sourceType)
 {
     return(_converter.CanConvertFrom(sourceType));
 }
Example #7
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            EnumItem item = value as EnumItem;

            if (item != null)
            {
                if (destinationType == typeof(String))
                {
                    return(item.ToString());
                }
                if (destinationType == typeof(UIElement))
                {
                    object displayValue = item.DisplayValue;
                    if (displayValue == null || displayValue is String)
                    {
                        TextBlock textBlock = new TextBlock();
                        textBlock.Text = item.ToString();
                        return(textBlock);
                    }
                    else if (displayValue is UIElement)
                    {
                        if (VisualTreeHelper.GetParent((UIElement)displayValue) != null)
                        {
                            // Clone UIElement to allow it to be used several times.
                            string       str = XamlWriter.Save(displayValue);
                            StringReader sr  = new StringReader(str);
                            XmlReader    xr  = XmlReader.Create(sr);
                            UIElement    ret = (UIElement)XamlReader.Load(xr);
                            return(ret);
                        }
                        else
                        {
                            return(displayValue);
                        }
                    }
                    if (displayValue is DataTemplate)
                    {
                        ContentPresenter presenter = new ContentPresenter();
                        presenter.Content         = item;
                        presenter.ContentTemplate = (DataTemplate)displayValue;
                        return(presenter);
                    }
                    else if (displayValue is Style)
                    {
                        TextBlock textBlock = new TextBlock();
                        textBlock.Style = (Style)displayValue;
                        textBlock.Text  = item.ToString();
                        return(textBlock);
                    }
                    else if (displayValue is ImageSource)
                    {
                        System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                        image.Source = (ImageSource)displayValue;
                        return(image);
                    }
                    else if (displayValue is Drawing)
                    {
                        System.Windows.Controls.Image image = new System.Windows.Controls.Image();
                        image.Source = new DrawingImage((Drawing)displayValue);
                        return(image);
                    }
                    else if (displayValue is System.Windows.Media.Brush)
                    {
                        TextBlock textBlock = new TextBlock();
                        textBlock.Background = (System.Windows.Media.Brush)displayValue;
                        textBlock.Text       = item.ToString();
                        return(textBlock);
                    }

                    else
                    {
                        TypeConverter converter = TypeDescriptor.GetConverter(displayValue);
                        if (converter.CanConvertTo(typeof(UIElement)))
                        {
                            UIElement element = converter.ConvertTo(context, culture, displayValue, typeof(UIElement)) as UIElement;
                            if (element != null)
                            {
                                return(element);
                            }
                        }
                        String text;
                        if (converter.CanConvertTo(typeof(string)))
                        {
                            text = converter.ConvertToString(context, culture, displayValue);
                        }
                        else
                        {
                            text = displayValue.ToString();
                        }
                        TextBlock textBlock = new TextBlock();
                        textBlock.Text = text;
                        return(textBlock);
                    }
                }
                if (destinationType == typeof(ImageSource))
                {
                    Object displayValue = item.DisplayValue;
                    if (displayValue == null || displayValue is ImageSource)
                    {
                        return(displayValue);
                    }
                    ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                    if (imageSourceConverter.CanConvertFrom(context, displayValue.GetType()))
                    {
                        object convertedValue = imageSourceConverter.ConvertFrom(context, culture, displayValue);
                        return(convertedValue);
                    }
                }
                else
                {
                    Object displayValue = item.DisplayValue;
                    if (displayValue == null || destinationType.IsAssignableFrom(displayValue.GetType()))
                    {
                        return(displayValue);
                    }
                    TypeConverter converter = TypeDescriptor.GetConverter(destinationType);
                    if (converter.CanConvertFrom(displayValue.GetType()))
                    {
                        object convertedValue = converter.ConvertFrom(context, culture, displayValue);
                        return(convertedValue);
                    }
                    else
                    {
                        Debug.Print("Unable to convert display value to target type: " + destinationType.FullName);
                        return(displayValue);
                    }
                }
            }
            return(null);
        }