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();
            });
        }
Exemplo n.º 2
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"));
     }
 }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 5
0
        /// <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));
        }
Exemplo n.º 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;
        }
Exemplo n.º 8
0
        public override void SetPresetValueString(string value)
        {
            object boxedColor = XamlBindingHelper.ConvertValue(typeof(Color), value);

            if (boxedColor is Color c)
            {
                Value = c;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 10
0
        private SolidColorBrush ColorConverter(string desiredColor)
        {
            var color = (Color)XamlBindingHelper.ConvertValue(typeof(Color), desiredColor);

            return(new SolidColorBrush
            {
                Color = color,
                Opacity = 0.3
            });
        }
        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);
        }
Exemplo n.º 12
0
 /// <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));
     }
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
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());
        }
Exemplo n.º 16
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                return((Brush)XamlBindingHelper.ConvertValue(typeof(Brush), value));
            }
            catch
            {
            }

            return(null);
        }
Exemplo n.º 17
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;
            }
        }
        /// <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));
        }
 void OnYearChanged()
 {
     if (_marker == null)
     {
         _marker = new TextBlock()
         {
             Opacity    = 0.1,
             Foreground = new SolidColorBrush((Color)XamlBindingHelper.ConvertValue(typeof(Color), "#00916f"))
         };
     }
     InvalidateMeasure();
     InvalidateArrange();
 }
Exemplo n.º 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));
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 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+");
            }
        }
Exemplo n.º 23
0
        public void PhaseElement(UIElement element, VirtualizationInfo virtInfo)
        {
            var  dataTemplateComponent = virtInfo.DataTemplateComponent;
            var  nextPhase             = virtInfo.Phase;
            bool shouldPhase           = false;

            if (nextPhase > 0)
            {
                if (dataTemplateComponent != null)
                {
                    // Perf optimization: RecyclingElementFactory sets up the virtualization info so we don't need to update it here.
                    shouldPhase = true;
                }
                else
                {
                    throw new InvalidOperationException("Phase was set on virtualization info, but dataTemplateComponent was not.");
                }
            }
            else if (nextPhase == VirtualizationInfo.PhaseNotSpecified)
            {
                // If virtInfo.Phase is not specified, virtInfo.DataTemplateComponent cannot be valid.
                global::System.Diagnostics.Debug.Assert(dataTemplateComponent == null);
                // ItemsRepeater might be using a custom view generator in which case, virtInfo would not be bootstrapped.
                // In this case, fallback to querying for the data template component and setup virtualization info now.
                dataTemplateComponent = XamlBindingHelper.GetDataTemplateComponent(element);
                if (dataTemplateComponent != null)
                {
                    // Clear out old data.
                    dataTemplateComponent.Recycle();

                    nextPhase = VirtualizationInfo.PhaseReachedEnd;
                    var index = virtInfo.Index;
                    var data  = m_owner.ItemsSourceView.GetAt(index);
                    // Run Phase 0
                    dataTemplateComponent.ProcessBindings(data, index, 0 /* currentPhase */, out nextPhase);

                    // Update phase on virtInfo. Set data and templateComponent only if x:Phase was used.
                    virtInfo.UpdatePhasingInfo(nextPhase, nextPhase > 0 ? data : null, nextPhase > 0 ? dataTemplateComponent : null);
                    shouldPhase = nextPhase > 0;
                }
            }

            if (shouldPhase)
            {
                // Insert at the top since we remove from bottom during DoPhasedWorkCallback. This keeps the ordering of items
                // the same as the order in which items are realized.
                m_pendingElements.Insert(0, new ElementInfo(element, virtInfo));
                RegisterForCallback();
            }
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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();
        }
Exemplo n.º 28
0
            protected override UIElement GetElementCore(ElementFactoryGetArgs args)
            {
                var element = _recyclePool.TryGetElement(key, args.Parent);

                if (element == null)
                {
                    element = new Button()
                    {
                        Width = 100, Height = 100
                    };
                }

                var elementManager = new ElementPhasingManager(_numPhases);

                XamlBindingHelper.SetDataTemplateComponent(element, elementManager);
                return(element);
            }
Exemplo n.º 29
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));
        }
Exemplo n.º 30
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);
        }