Beispiel #1
0
 public Color GetColor(string myColor)
 {
     if (myColor == "RED")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "RED"));
     }
     else if (myColor == "GREEN")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "GREEN"));
     }
     else if (myColor == "PURPLE")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "PURPLE"));
     }
     else if (myColor == "OLIVE")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "OLIVE"));
     }
     else if (myColor == "SADDLEBROWN")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "SADDLEBROWN"));
     }
     else if (myColor == "DEEPPINK")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "DEEPPINK"));
     }
     else if (myColor == "BLUE")
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "BLUE"));
     }
     else
     {
         return((Color)XamlBindingHelper.ConvertValue(typeof(Color), "BLACK"));
     }
 }
Beispiel #2
0
        public void ImageRefresh()
        {
            ImagePreviewProgressRing.Visibility = Visibility.Visible;
            ImagePreviewProgressRing.IsActive   = true;
            ImagePreviewSymbolIcon.Visibility   = Visibility.Collapsed;
            ImagePreviewImage.Visibility        = Visibility.Collapsed;
            // こっちのほうが画像がキャッシュされるような気がする(気のせい)
            ImagePreviewImage.Source =
                (ImageSource)XamlBindingHelper.ConvertValue(typeof(ImageSource), Images[ImageIndex].MediaUrl);
            _imageOpened = false;

            if (ImageIndex <= 0 || Images.Count <= 1)
            {
                ImagePreviewPreviousButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                ImagePreviewPreviousButton.Visibility = Visibility.Visible;
            }

            if (ImageIndex >= Images.Count - 1 || Images.Count <= 1)
            {
                ImagePreviewNextButton.Visibility = Visibility.Collapsed;
            }
            else
            {
                ImagePreviewNextButton.Visibility = Visibility.Visible;
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // It is recommended to only retrieve the ShareOperation object in the activation handler, return as
            // quickly as possible, and retrieve all data from the share target asynchronously.

            var   appDetails = (AppDetails)e.Parameter;
            Color bgColor;

            try {
                bgColor = (Color)XamlBindingHelper.ConvertValue(typeof(Color), appDetails.backgroundColor);
            } catch {
                // handle unspecified background colour - happens for some tiles such as Whatsapp.
                bgColor = Colors.Transparent;
            }

            // Some app tiles can also define 'transparent' colour - which will be
            // transformed to the system accent colour.
            if (bgColor.Equals(Colors.Transparent))
            {
                bgColor = (Color)this.Resources["SystemAccentColor"];
            }

            // Get back to the UI thread using the dispatcher.
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                var fill                        = new SolidColorBrush(bgColor);
                appImage.Source                 = new BitmapImage(new Uri(appDetails.image));
                appImageBg.Fill                 = fill;
                appImageHeroBg.Fill             = fill;
                appName.Text                    = appDetails.name;
                appReleaseDate.Text             = appDetails.releaseDate.ToLocalTime().ToString();
                appReleaseDateRelative.Text     = appDetails.releaseDate.Humanize();
                appLastUpdatedDate.Text         = appDetails.lastUpdatedDate.ToLocalTime().ToString();
                appLastUpdatedDateRelative.Text = appDetails.lastUpdatedDate.Humanize();
            });
        }
Beispiel #4
0
        private void OnValueStringChanged(string oldValue, string newValue)
        {
            if (!_internalValueChanging)
            {
                Color c;
                try
                {
                    var boxedColor = XamlBindingHelper.ConvertValue(typeof(Color), newValue);
                    if (boxedColor == null)
                    {
                        return;
                    }
                    c = (Color)boxedColor;
                }
                catch
                {
                    return;
                }

                _internalValueChanging = true;

                UpdateProperties(c);

                _internalValueChanging = false;
            }
        }
        /// <summary>
        /// Convert value to brush
        /// </summary>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double _value;

            if (!String.IsNullOrEmpty(value.ToString()))
            {
                _value = double.Parse(value.ToString(), NumberStyles.Currency);

                if (_value > 30)
                {
                    LinearGradientBrush Brush2 = new LinearGradientBrush();

                    GradientStop gradientStop1 = new GradientStop();
                    gradientStop1.Color  = Colors.White;
                    gradientStop1.Offset = 0;
                    Brush2.GradientStops.Add(gradientStop1);

                    GradientStop gradientStop2 = new GradientStop();
                    gradientStop2.Color  = (Color)XamlBindingHelper.ConvertValue(typeof(Windows.UI.Color), "#94C3FF");
                    gradientStop2.Offset = 1;
                    Brush2.GradientStops.Add(gradientStop2);
                    return(Brush2);
                }
            }
            return(new SolidColorBrush());
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var color = (Color)XamlBindingHelper.ConvertValue(typeof(Color), counter % 2 == 0 ? "#333333" : "#000000");

            counter++;
            return(new SolidColorBrush(color));
        }
Beispiel #7
0
        public void Update()
        {
            ellipse.Fill   = Color;
            ellipse.Width  = Bot.Radius * 2;
            ellipse.Height = Bot.Radius * 2;
            Canvas.SetLeft(ellipse, Bot.Position.X - Bot.Radius);
            Canvas.SetTop(ellipse, Bot.Position.Y - Bot.Radius);

            var outlineColor = Colors.Black;

            if (App.Current.RequestedTheme == ApplicationTheme.Dark)
            {
                outlineColor = Colors.White;
            }

            line.Stroke = new SolidColorBrush(outlineColor);

            if (IsSelected)
            {
                var col = GetColor(((Bot.Color.GetHue() + 180) % 360) / 360, Bot.Color.GetSaturation(), Bot.Color.GetBrightness());
                ellipse.Stroke          = new SolidColorBrush(col);
                ellipse.StrokeThickness = 3;

                for (var i = 0; i < Bot.EyeCount; i++)
                {
                    visionPath[i].Visibility = Visibility.Visible;
                    visionPath[i].Stroke     = new SolidColorBrush(col);
                    var visionRadius = Bot.VisionLimit - Bot.EyeDistances[i];

                    var eyePosition = i - Bot.EyeCount / 2;
                    var eyeStart    = (eyePosition * Bot.EyeAngle * 2) - Bot.EyeAngle;
                    var eyeStop     = (eyePosition * Bot.EyeAngle * 2) + Bot.EyeAngle;

                    var arcStartX = visionRadius * Math.Cos(Bot.Orientation + eyeStart);
                    var arcStartY = visionRadius * Math.Sin(Bot.Orientation + eyeStart);
                    var arcEndX   = visionRadius * Math.Cos(Bot.Orientation + eyeStop);
                    var arcEndY   = visionRadius * Math.Sin(Bot.Orientation + eyeStop);

                    visionPath[i].Data = (Geometry)XamlBindingHelper.ConvertValue(typeof(Geometry), $"M0,0 L{arcStartX},{arcStartY} A{visionRadius},{visionRadius} 0 0 1 {arcEndX},{arcEndY} z");
                    Canvas.SetLeft(visionPath[i], Bot.Position.X);
                    Canvas.SetTop(visionPath[i], Bot.Position.Y);
                }
            }
            else
            {
                ellipse.Stroke          = new SolidColorBrush(outlineColor);
                ellipse.StrokeThickness = 2;
                foreach (var p in visionPath)
                {
                    p.Visibility = Visibility.Collapsed;
                }
            }

            line.X1           = Bot.Position.X;
            line.Y1           = Bot.Position.Y;
            line.X2           = Bot.Position.X + Bot.Radius * Math.Cos(Bot.Orientation);
            line.Y2           = Bot.Position.Y + Bot.Radius * Math.Sin(Bot.Orientation);
            line.IsTapEnabled = true;
        }
Beispiel #8
0
        public override void SetPresetValueString(string value)
        {
            object boxedColor = XamlBindingHelper.ConvertValue(typeof(Color), value);

            if (boxedColor is Color c)
            {
                Value = c;
            }
        }
Beispiel #9
0
        public override bool ComparePresetValueString(string value)
        {
            object boxedColor = XamlBindingHelper.ConvertValue(typeof(Color), value);

            if (boxedColor is Color c)
            {
                return(c == _selectedColor);
            }
            return(false);
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            Debug.WriteLine("Status: " + value + ", Parameter: " + parameter + ", Type: " + targetType);
            SolidColorBrush brush       = new SolidColorBrush();
            Color           targetColor = (Color)XamlBindingHelper.ConvertValue(typeof(Color), parameter);

            brush.Color = ((bool)value) ? targetColor : Colors.Gray;

            return(brush);
        }
Beispiel #11
0
        private SolidColorBrush ColorConverter(string desiredColor)
        {
            var color = (Color)XamlBindingHelper.ConvertValue(typeof(Color), desiredColor);

            return(new SolidColorBrush
            {
                Color = color,
                Opacity = 0.3
            });
        }
Beispiel #12
0
        public FrameworkElement GetNativeSplashScreen(SplashScreen splashScreen)
        {
            var splashScreenImage      = new Image();
            var splashScreenBackground = new SolidColorBrush();
            var scaleFactor            = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

            var splashScreenElement = new Canvas
            {
                Background = splashScreenBackground,
                Children   = { splashScreenImage },
            };

            try
            {
                var doc        = XDocument.Load("AppxManifest.xml", LoadOptions.None);
                var xnamespace = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10");

                var visualElementsNode          = doc.Descendants(xnamespace + "VisualElements").First();
                var splashScreenNode            = visualElementsNode.Descendants(xnamespace + "SplashScreen").First();
                var splashScreenImagePath       = splashScreenNode.Attribute("Image").Value;
                var splashScreenBackgroundColor = splashScreenNode.Attribute("BackgroundColor")?.Value;

                splashScreenImage.Source     = new BitmapImage(new Uri("ms-appx:///" + splashScreenImagePath));
                splashScreenBackground.Color = splashScreenBackgroundColor != null
                                        ? (Color)XamlBindingHelper.ConvertValue(typeof(Color), splashScreenBackgroundColor)
                                        : Colors.White;
            }
            catch (Exception e)
            {
                typeof(ExtendedSplashScreen).Log().LogError(0, e, "Error while getting native splash screen.");
            }

            void PositionImage()
            {
                splashScreenImage.SetValue(Canvas.LeftProperty, splashScreen.ImageLocation.Left);
                splashScreenImage.SetValue(Canvas.TopProperty, splashScreen.ImageLocation.Top);
                if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
                {
                    splashScreenImage.Height = splashScreen.ImageLocation.Height / scaleFactor;
                    splashScreenImage.Width  = splashScreen.ImageLocation.Width / scaleFactor;
                }
                else
                {
                    splashScreenImage.Height = splashScreen.ImageLocation.Height;
                    splashScreenImage.Width  = splashScreen.ImageLocation.Width;
                }
            }

            Window.Current.SizeChanged += (s, e) => PositionImage();

            PositionImage();

            return(splashScreenElement);
        }
 /// <summary>
 /// Helper method to convert a value from a source type to a target type.
 /// </summary>
 /// <param name="value">The value to convert</param>
 /// <param name="targetType">The target type</param>
 /// <returns>The converted value</returns>
 internal static object Convert(object value, Type targetType)
 {
     if (targetType.IsInstanceOfType(value))
     {
         return(value);
     }
     else
     {
         return(XamlBindingHelper.ConvertValue(targetType, value));
     }
 }
Beispiel #14
0
        public Task ShowProductPopup(ProductViewModel info)
        {
            ContentDialog content = new ContentDialog
            {
                ContentTemplate   = (DataTemplate)App.Current.Resources["ContentDialogProductInfo"],
                DataContext       = info,
                Background        = new SolidColorBrush((Color)XamlBindingHelper.ConvertValue(typeof(Color), info.BgColor)),
                PrimaryButtonText = "Ok",
            };

            return(content.ShowAsync().AsTask());
        }
Beispiel #15
0
        public void SetValue(string value)
        {
            ColorSpectrum colorSpectrumOwner = _owner;
            Color         color = (Color)(XamlBindingHelper.ConvertValue(typeof(Color), value));

            colorSpectrumOwner.Color = color;

            // Since ColorPicker sets ColorSpectrum.Color and ColorPicker also responds to ColorSpectrum.ColorChanged,
            // we could get into an infinite loop if we always raised ColorSpectrum.ColorChanged when ColorSpectrum.Color changed.
            // Because of that, we'll raise the event manually.
            colorSpectrumOwner.RaiseColorChanged();
        }
Beispiel #16
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                return((Brush)XamlBindingHelper.ConvertValue(typeof(Brush), value));
            }
            catch
            {
            }

            return(null);
        }
Beispiel #17
0
        /// <summary>
        /// Change pencil color
        /// </summary>
        private void ColorBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            InkDrawingAttributes ida = new InkDrawingAttributes();

            Rectangle b = (Rectangle)e.AddedItems[0];

            var color = (Color)XamlBindingHelper.ConvertValue(typeof(Color), b.Name);

            ida.Color = color;

            colorRectangle.Fill = new SolidColorBrush(color);
            PaintCanvas.InkPresenter.StrokeInput.InkPresenter.UpdateDefaultDrawingAttributes(ida);
        }
        /// <summary>Converts the specified value.</summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="language">The language.</param>
        /// <returns>
        ///   <br />
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            string colorString = value as string;

            if (string.IsNullOrEmpty(colorString))
            {
                return(new SolidColorBrush(Colors.Black));
            }

            Color color = (Color)XamlBindingHelper.ConvertValue(typeof(Color), colorString);

            return(new SolidColorBrush(color));
        }
Beispiel #19
0
        public override void SetPresetValueString(string value)
        {
            object boxedColor = XamlBindingHelper.ConvertValue(typeof(Color), value);

            if (boxedColor is Color c)
            {
                if (!_colors.Contains(c))
                {
                    CustomColor = c;
                }
                SelectedColor = c;
            }
        }
Beispiel #20
0
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            if (value is string strValue && parameter is string str && !string.IsNullOrWhiteSpace(str))
            {
                int indx = strValue.LastIndexOf(str);
                if (indx != -1)
                {
                    value = strValue.Remove(indx);
                }
            }

            return(XamlBindingHelper.ConvertValue(targetType, value));
        }
 void OnYearChanged()
 {
     if (_marker == null)
     {
         _marker = new TextBlock()
         {
             Opacity    = 0.1,
             Foreground = new SolidColorBrush((Color)XamlBindingHelper.ConvertValue(typeof(Color), "#00916f"))
         };
     }
     InvalidateMeasure();
     InvalidateArrange();
 }
Beispiel #22
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            int number = (int)value;

            if (number < 99)
            {
                return(XamlBindingHelper.ConvertValue(targetType, value));
            }
            else
            {
                return("99+");
            }
        }
Beispiel #23
0
        public static Windows.UI.Color FromHex(string hexString)
        {
            Windows.UI.Color x;

            try
            {
                x = (Windows.UI.Color)XamlBindingHelper.ConvertValue(typeof(Windows.UI.Color), hexString);
            }
            catch (ArgumentException)
            {
                x = Windows.UI.Colors.Black;
            }

            return(x);
        }
Beispiel #24
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (targetType != typeof(string))
            {
                return(value);
            }

            string ret = (string)XamlBindingHelper.ConvertValue(targetType, value);

            if (parameter is string str && !string.IsNullOrWhiteSpace(str))
            {
                return($"{ret}{str}");
            }

            return(ret);
        }
Beispiel #25
0
        public static Windows.UI.Color FromHex(string fillColor, double opacity)
        {
            Windows.UI.Color x;

            try
            {
                x   = (Windows.UI.Color)XamlBindingHelper.ConvertValue(typeof(Windows.UI.Color), fillColor);
                x.A = Convert.ToByte(opacity);
            }
            catch (ArgumentException)
            {
                x = Windows.UI.Colors.Black;
            }

            return(x);
        }
        private void OnPathDataPropertyChanged(DependencyPropertyChangedEventArgs args)
        {
            // A Geometry is not a shareable resource. That is why a path-data string is dynamically converted to Geometry for each button instance.

            string pathdata = args.NewValue as string;

            if (pathdata == null)
            {
                _geometry = null;
            }
            else
            {
                _geometry = (Geometry)XamlBindingHelper.ConvertValue(typeof(Geometry), pathdata);
            }

            ResetControls();
        }
Beispiel #27
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var colors      = new[] { "#FF00FF00", "#FFFF0000" };
            var paramString = parameter as string;
            var input       = System.Convert.ToBoolean(value);

            if (!string.IsNullOrEmpty(paramString))
            {
                colors = paramString.Split(new char[] { '|' });
            }

            var resultColor = input ? colors[0] : colors[1];

            Color x = (Color)XamlBindingHelper.ConvertValue(typeof(Color), resultColor);

            return(new SolidColorBrush(x));
        }
Beispiel #28
0
        private async Task <SecondaryTile> CreateTile(AppModel model)
        {
            var iconPath = await AppIconsManager.Current.CopyToLocalAppData(model.TileIconPath);

            var appTile = new SecondaryTile(
                model.TileId,
                model.Name,
                model.Id,
                new Uri(iconPath),
                TileSize.Default);

            appTile.RoamingEnabled = true;
            appTile.VisualElements.BackgroundColor             = (Windows.UI.Color)XamlBindingHelper.ConvertValue(typeof(Windows.UI.Color), model.AccentColor);
            appTile.VisualElements.ShowNameOnSquare150x150Logo = true;

            return(appTile);
        }
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            try
            {
                if (value as string == "Null")
                {
                    return(null);
                }

                Color           c   = (Color)XamlBindingHelper.ConvertValue(typeof(Color), value);
                SolidColorBrush scb = new SolidColorBrush(c);
                return(scb);
            }
            catch (FormatException)
            {
                return(value);
            }
        }
        //// Called whenever changes to the document are made, should identify colors in text and return the actual color value as well as where it was found in the text.
        public IAsyncOperation <IEnumerable <ColorInformation> > ProvideDocumentColorsAsync(IModel document)
        {
            return(AsyncInfo.Run(async delegate(CancellationToken cancelationToken)
            {
                var info = new List <ColorInformation>();

                // Find all the 8 long hex values we can find in the document using regex.
                var matches = await document.FindMatchesAsync("#[A-Fa-f0-9]{8}", true, true, true, null, true);

                foreach (var match in matches)
                {
                    // Generate color info for each of these matches by using the XAML converter to read it to a Color value.
                    info.Add(new ColorInformation(XamlBindingHelper.ConvertValue(typeof(Color), match.Matches.First()) as Color? ?? Colors.Black, match.Range));
                }

                return info.AsEnumerable();
            }));
        }