상속: GradientBrush, ILinearGradientBrush
예제 #1
0
파일: Carousel.cs 프로젝트: ridomin/waslibs
        protected override void OnApplyTemplate()
        {
            _frame = base.GetTemplateChild("frame") as Panel;
            _panel = base.GetTemplateChild("panel") as CarouselPanel;

            _arrows = base.GetTemplateChild("arrows") as Grid;
            _left = base.GetTemplateChild("left") as Button;
            _right = base.GetTemplateChild("right") as Button;

            _gradient = base.GetTemplateChild("gradient") as LinearGradientBrush;
            _clip = base.GetTemplateChild("clip") as RectangleGeometry;

            _frame.ManipulationDelta += OnManipulationDelta;
            _frame.ManipulationCompleted += OnManipulationCompleted;
            _frame.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.System;

            _frame.PointerMoved += OnPointerMoved;
            _left.Click += OnLeftClick;
            _right.Click += OnRightClick;
            _left.PointerEntered += OnArrowPointerEntered;
            _left.PointerExited += OnArrowPointerExited;
            _right.PointerEntered += OnArrowPointerEntered;
            _right.PointerExited += OnArrowPointerExited;

            base.OnApplyTemplate();
        }
예제 #2
0
        private static LinearGradientBrush CreateGradientBrush(Orientation orientation, params Color[] colors)
        {
            var brush = new LinearGradientBrush();
            var negatedStops = 1 / (float)colors.Length;

            for (var i = 0; i < colors.Length; i++)
            {
                brush.GradientStops.Add(new GradientStop { Offset = negatedStops * i, Color = colors[i] });
            }

            // creating the full loop
            brush.GradientStops.Add(new GradientStop { Offset = negatedStops * colors.Length, Color = colors[0] });

            if (orientation == Orientation.Vertical)
            {
                brush.StartPoint = new Point(0, 1);
                brush.EndPoint = new Point();
            }
            else
            {
                brush.EndPoint = new Point(1, 0);
            }

            return brush;
        }
        public GradientBrushCodePage() {
            this.InitializeComponent();

            // Create the foreground brush for the TextBlock
            LinearGradientBrush foregroundBrush = new LinearGradientBrush();
            foregroundBrush.StartPoint = new Point(0, 0);
            foregroundBrush.EndPoint = new Point(1, 0);

            GradientStop gradientStop = new GradientStop();
            gradientStop.Offset = 0;
            gradientStop.Color = Colors.Blue;
            foregroundBrush.GradientStops.Add(gradientStop);

            gradientStop = new GradientStop();
            gradientStop.Offset = 1;
            gradientStop.Color = Colors.Red;
            foregroundBrush.GradientStops.Add(gradientStop);

            txtblk.Foreground = foregroundBrush;

            // Create the background brush for the Grid
            LinearGradientBrush backgroundBrush = new LinearGradientBrush {StartPoint = new Point(0, 0), EndPoint = new Point(1, 0)};
            backgroundBrush.GradientStops.Add(new GradientStop { Offset = 0, Color = Colors.Red });
            backgroundBrush.GradientStops.Add(new GradientStop { Offset = 1, Color = Colors.Blue });
            contentGrid.Background = backgroundBrush;
        }
        private void UpdateBorder(PancakeView pancake)
        {
            //// Create the border layer
            if (content != null && pancake.Border != null)
            {
                this.content.BorderThickness = new Windows.UI.Xaml.Thickness(pancake.Border.Thickness);

                if (pancake.Border.GradientStops != null && pancake.Border.GradientStops.Any())
                {
                    // A range of colors is given. Let's add them.
                    var orderedStops = pancake.Border.GradientStops.OrderBy(x => x.Offset).ToList();
                    var gc           = new Windows.UI.Xaml.Media.GradientStopCollection();

                    foreach (var item in orderedStops)
                    {
                        gc.Add(new Windows.UI.Xaml.Media.GradientStop {
                            Offset = item.Offset, Color = item.Color.ToWindowsColor()
                        });
                    }

                    var gradient = new Windows.UI.Xaml.Media.LinearGradientBrush(gc, 0);
                    gradient.StartPoint = new Windows.Foundation.Point(pancake.Border.GradientStartPoint.X, pancake.Border.GradientStartPoint.Y);
                    gradient.EndPoint   = new Windows.Foundation.Point(pancake.Border.GradientEndPoint.X, pancake.Border.GradientEndPoint.Y);

                    this.content.BorderBrush = gradient;
                }
                else
                {
                    this.content.BorderBrush = pancake.Border.Color.IsDefault ? null : pancake.Border.Color.ToBrush();
                }
            }
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var brush = new LinearGradientBrush();
            brush.StartPoint = new Point(1, 0.5);
            brush.EndPoint = new Point(0, 0.5);

            var isActive = (bool) value;
            if (isActive)
            {
                brush.GradientStops.Add(new GradientStop
                {
                    Offset = 0.184,
                    Color = Color.FromArgb(255, 255, 92, 0)
                });
                brush.GradientStops.Add(new GradientStop
                {
                    Offset = 389,
                    Color = Color.FromArgb(255, 255, 187, 0)
                });
                return brush;
            }
            brush.GradientStops.Add(new GradientStop
            {
                Offset = 0.184,
                Color = Color.FromArgb(255, 255, 187, 0)
            });
            brush.GradientStops.Add(new GradientStop
            {
                Offset = 389,
                Color = Color.FromArgb(255, 255, 255, 255)
            });
            return brush;
        }
        protected override void UpdateBackgroundColor()
        {
            // background color change must be handled separately
            // because the background would protrude through the border if the corners are rounded
            // as the background would be applied to the renderer's FrameworkElement
            var pancake = (PancakeView)Element;

            if (content != null)
            {
                if (pancake.BackgroundGradientStops != null && pancake.BackgroundGradientStops.Any())
                {
                    // A range of colors is given. Let's add them.
                    var orderedStops = pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList();
                    var gc           = new Windows.UI.Xaml.Media.GradientStopCollection();

                    foreach (var item in orderedStops)
                    {
                        gc.Add(new Windows.UI.Xaml.Media.GradientStop {
                            Offset = item.Offset, Color = item.Color.ToWindowsColor()
                        });
                    }

                    var gradient = new Windows.UI.Xaml.Media.LinearGradientBrush(gc, 0);
                    gradient.StartPoint     = new Windows.Foundation.Point(pancake.BackgroundGradientStartPoint.X, pancake.BackgroundGradientStartPoint.Y);
                    gradient.EndPoint       = new Windows.Foundation.Point(pancake.BackgroundGradientEndPoint.X, pancake.BackgroundGradientEndPoint.Y);
                    this.content.Background = gradient;
                }
                else
                {
                    content.Background = Element.BackgroundColor.IsDefault ? null : Element.BackgroundColor.ToBrush();
                }
            }
        }
예제 #7
0
        public GradientButton() {
            gradientStop1 = new GradientStop { Offset = 0, Color = this.Color1 };
            gradientStop2 = new GradientStop { Offset = 1, Color = this.Color2 };

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.GradientStops.Add(gradientStop1);
            brush.GradientStops.Add(gradientStop2);

            this.Foreground = brush;
        }
 /// <summary>
 /// Updates the fill.
 /// </summary>
 /// <param name="stops">The stops.</param>
 public void UpdateFill(GradientStopCollection stops)
 {
     var brush = Background as LinearGradientBrush;
     if (brush == null || brush.GradientStops != stops)
     {
         Background = new LinearGradientBrush
         {
             StartPoint = new Point(0, 0),
             EndPoint = new Point(0, 1),
             GradientStops = stops
         };
     }
 }
        public static Brush DrawField(bool white)
        {
            LinearGradientBrush brush = new LinearGradientBrush();

            brush.StartPoint = white ? new Point(0, 0) : new Point(0, 1);
            brush.EndPoint = white ? new Point(1, 1) : new Point(1, 0);
            GradientStop stop1 = new GradientStop();
            stop1.Color = white ? Color.FromArgb(255, 239, 231, 186) : Color.FromArgb(255, 254, 0, 0);
            stop1.Offset = 0.5;
            brush.GradientStops.Add(stop1);
            GradientStop stop2 = new GradientStop();
            stop2.Color = white ? Color.FromArgb(255, 191, 167, 127) : Color.FromArgb(255, 169, 0, 0);
            stop2.Offset = 1;
            brush.GradientStops.Add(stop2);
            return brush;
        }
예제 #10
0
		public BrokenNativeControl ()
		{
			_textBlock = new TextBlock {
				MinHeight = 0,
				MaxHeight = double.PositiveInfinity,
				MinWidth = 0,
				MaxWidth = double.PositiveInfinity,
				FontSize = 24,
				HorizontalAlignment = HorizontalAlignment.Center
			};

			Children.Add (_textBlock);

			Background =
				new LinearGradientBrush (
					new GradientStopCollection { new GradientStop { Color = Colors.Green, Offset = 0.5}, new GradientStop { Color = Colors.Blue, Offset = 1} }, 0);
		}
예제 #11
0
        void FlatNavigationPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Current = this;

            AppBar appBar = new AppBar();
            appBar.Content = new FlatNavigationControl();
            this.TopAppBar = appBar;

            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
            myLinearGradientBrush.StartPoint = new Point(0, 0);
            myLinearGradientBrush.EndPoint = new Point(1, 1);
            GradientStop gradientStop = new GradientStop();

            myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Colors.AliceBlue, Offset = 0 });
            myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Colors.Magenta, Offset = 1 });

            this.Background = myLinearGradientBrush;
        }
예제 #12
0
        /// <summary>
        /// Returns a Windows brush from the NGraphics brush
        /// </summary>
        /// <param name="fromBrush"></param>
        /// <returns></returns>
        private Windows.UI.Xaml.Media.Brush GetBrush(NGraphics.Brush fromBrush)
        {
            var sb = fromBrush as SolidBrush;
            if(sb != null)
            {                
                // Solid brush
                return new SolidColorBrush(new Windows.UI.Color { 
                    A = sb.Color.A, R = sb.Color.R, G = sb.Color.G, B = sb.Color.B
                });
            }
            
            var lb = fromBrush as NGraphics.LinearGradientBrush;
            if(lb != null)
            {
                // Linear gradient
                var gradStops = new GradientStopCollection();
                var n = lb.Stops.Count;                
                if (n >= 2)
                {
                    var locs = new float[n];
                    var comps = new int[n];
                    for (var i = 0; i < n; i++)
                    {
                        var s = lb.Stops[i];
                        gradStops.Add(new Windows.UI.Xaml.Media.GradientStop
                        {
                            Color = new Windows.UI.Color { 
                                A = s.Color.A,
                                R = s.Color.R,
                                B = s.Color.B,
                                G = s.Color.G,
                            },
                            Offset = s.Offset,
                        });                        
                    }                    
                }

                var grad = new Windows.UI.Xaml.Media.LinearGradientBrush(gradStops, 90);
                return grad;
            }

            var rb = fromBrush as NGraphics.RadialGradientBrush;
            if(rb != null)
            {
                // Radial gradient
                throw new NotSupportedException("RadialGradientBrush is not supported for Windws Store Apps.");
                //var grad = new Windows.UI.Xaml.Media.RadialGradientBrush();
                //var n = rb.Stops.Count;
                //if (n >= 2)
                //{
                //    var locs = new float[n];
                //    var comps = new int[n];
                //    for (var i = 0; i < n; i++)
                //    {
                //        var s = rb.Stops[i];
                //        grad.GradientStops.Add(new Windows.UI.Xaml.Media.GradientStop
                //        {
                //            Color = new Windows.UI.Color
                //            {
                //                A = s.Color.A,
                //                R = s.Color.R,
                //                B = s.Color.B,
                //                G = s.Color.G,
                //            },
                //            Offset = s.Offset,
                //        });
                //    }
                //}
                //return grad;
            }

            return null;
        }
        public GradientEffectComposition(UIElement element, LinearGradientBrush gradient)
        {
            Element = element as Panel;
            Gradient = gradient;

            ContainerVisual = element.GetContainerVisual();
            Compositor = ContainerVisual.Compositor;

            InitializeAnimations();
            SetGradient(gradient);
        }
예제 #14
0
        /// <summary>
        /// Populates list from response of web service
        /// </summary>
        /// <param name="ReportsList"></param>
        private async void PopulateQueue(ObservableCollection<ReportObject> QueuedList, IReadOnlyList<StorageFile> pf)
        {
            //if (refreshMap)
            //{
            //    ClearMap();
            //}

            queuedObjectList.Clear();

            int count = 0;
            foreach (var Que in QueuedList)
            {
                Image image = new Image();
                count++;
                var file = await pictureFolder.GetFileAsync(count + "_" + Que.ReportType.ToString() + ".png");

                var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                var img = new BitmapImage();
                img.SetSource(fileStream);

                image.Source = img;

                GridViewItem ReportView = new GridViewItem();
                GridViewItem ImageView = new GridViewItem();

                StackPanel listSP = new StackPanel();

                LinearGradientBrush lgb = new LinearGradientBrush();

                lgb.StartPoint = new Point(.5, 0);
                lgb.EndPoint = new Point(.5, 1);

                GradientStop lggs = new GradientStop();
                lggs.Color = Color.FromArgb(255, 217, 214, 203);
                lggs.Offset = 0.0;
                lgb.GradientStops.Add(lggs);

                GradientStop ggs = new GradientStop();
                ggs.Color = Color.FromArgb(255, 108, 108, 108);
                ggs.Offset = 1.25;
                lgb.GradientStops.Add(ggs);

                listSP.Background = lgb;

                listSP.Orientation = Orientation.Horizontal;

                StackPanel reportSP = new StackPanel();

                queuedListIndex.Add(Que.ReportId);

                TextBlock ridTB = new TextBlock() { Text = Que.ReportId.ToString() };
                ridTB.Foreground = new SolidColorBrush(Colors.Black);
                reportSP.Children.Add(ridTB);

                TextBlock rtypeTB = new TextBlock() { Text = Que.ReportType };
                rtypeTB.Foreground = new SolidColorBrush(Colors.Black);
                reportSP.Children.Add(rtypeTB);

                TextBlock rtimeTB = new TextBlock() { Text = Que.ReportTime.ToString() };
                rtimeTB.Foreground = new SolidColorBrush(Colors.Black);
                reportSP.Children.Add(rtimeTB);

                ReportObject queuedReportObject = new ReportObject(Que.ReportId,
                                                                   Que.ReportType,
                                                                   Que.ReportAuthor,
                                                                   Que.ReportDescription,
                                                                   Que.ReportLocation,
                                                                   Que.ReportTime,
                                                                   Que.ReportLatitude,
                                                                   Que.ReportLongitude,
                                                                   Que.ReportAccuracy,
                                                                   Que.ReportDirection);

                queuedObjectList.Add(queuedReportObject);

                if (!(queuedReportObject.ReportLatitude == "NA" || queuedReportObject.ReportLongitude == "NA"))
                {
                    try
                    {
                        AddToMap(queuedReportObject);
                    }
                    catch (Exception) { }
                }

                image.Height = 110;
                image.Width = 175;

                ImageView.Content = image;
                ReportView.Content = reportSP;
                ImageView.AddHandler(UIElement.TappedEvent, new TappedEventHandler(QImageSelected), true);
                ReportView.AddHandler(UIElement.TappedEvent, new TappedEventHandler(QReportSelected), true);

                listSP.Children.Add(ReportView);
                listSP.Children.Add(ImageView);
                QueuedListView.Items.Add(listSP);
            }
            if (count > 0)
            {
                if (SIUC311.SettingsView.GetAutoSubmitSetting())
                {
                    await WaitablePromptMessage("You have " + count + " reports queued\n\nQueued reports will be automatically submitted.");
                }
                else
                {
                    await WaitablePromptMessage("You have " + count + " reports queued.");
                }
                if (haveInternetAccess)
                {
                    //NotifyUser("Processing queue . . . ", NotifyType.ReportMessage);
                    try
                    {
                        inSession = await SIU311Service.IsSessionAliveAsync(sessionId); // SLOW TAKES TIME 
                    }
                    catch (Exception)
                    {
                        inSession = false;
                    }
                    //NotifyUser("Session checked at " + string.Format("{0:M/d/yyyy H:mm:ss tt}", DateTime.Now), NotifyType.ReportMessage);
                    if (inSession)
                    {
                        if (SIUC311.SettingsView.GetAutoSubmitSetting())
                        {
                            await SubmitQueue();
                        }
                    }
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Populates list from response of web service
        /// </summary>
        /// <param name="ReportsList"></param>
        private async void PopulateList(ObservableCollection<SIUC311ServiceRef.ReportObject> ReportsList, bool byOwner)
        {
            // add condition from checkbox
            if (refreshMap)
            {
                ClearMap();
                reportObjectList.Clear();
            }            

            foreach (var Rep in ReportsList)
            {
                Image image = new Image();

                var photoObject = await SIU311Service.GetPhotoAsync(Rep.ReportId);

                BitmapImage bimage;

                if (photoObject != null && photoObject.ReportPhoto != null)
                {
                    bimage = await ByteToImage(photoObject.ReportPhoto);
                }
                else
                {
                    bimage = new BitmapImage(new Uri("ms-appx:///Assets/ImagePlaceHolder.png"));
                }

                string status = await SIU311Service.GetStatusAsync(Rep.ReportId);

                image.Source = bimage;

                GridViewItem ReportView = new GridViewItem();
                GridViewItem ImageView = new GridViewItem();

                StackPanel listSP = new StackPanel();

                LinearGradientBrush lgb = new LinearGradientBrush();

                lgb.StartPoint = new Point(.5, 0);
                lgb.EndPoint = new Point(.5, 1);

                GradientStop lggs = new GradientStop();
                lggs.Color = Color.FromArgb(255, 217, 214, 203);
                lggs.Offset = 0.0;
                lgb.GradientStops.Add(lggs);

                GradientStop ggs = new GradientStop();
                ggs.Color = Color.FromArgb(255, 108, 108, 108);
                ggs.Offset = 1.25;
                lgb.GradientStops.Add(ggs);

                listSP.Background = lgb;

                listSP.Orientation = Orientation.Horizontal;

                StackPanel reportSP = new StackPanel();

                reportListIndex.Add(Rep.ReportId);

                StackPanel idStatusSP = new StackPanel();
                idStatusSP.Orientation = Orientation.Horizontal;

                TextBlock ridTB = new TextBlock() { Text = Rep.ReportId.ToString() };
                ridTB.Foreground = new SolidColorBrush(Colors.Black);

                TextBlock statusTB = new TextBlock() { Text = " : " + status };
                statusTB.Foreground = new SolidColorBrush(Colors.Black);

                idStatusSP.Children.Add(ridTB);
                idStatusSP.Children.Add(statusTB);

                reportSP.Children.Add(idStatusSP);

                TextBlock rtypeTB = new TextBlock() { Text = Rep.ReportType };
                rtypeTB.Foreground = new SolidColorBrush(Colors.Black);
                reportSP.Children.Add(rtypeTB);

                if (!byOwner)
                {
                    TextBlock rownTB = new TextBlock() { Text = Rep.ReportAuthor };
                    rownTB.Foreground = new SolidColorBrush(Colors.Black);
                    reportSP.Children.Add(rownTB);
                }

                TextBlock rtimeTB = new TextBlock() { Text = Rep.ReportTime.ToString() };
                rtimeTB.Foreground = new SolidColorBrush(Colors.Black);
                reportSP.Children.Add(rtimeTB);

                ReportObject reportObject = new ReportObject(Rep.ReportId,
                                                             Rep.ReportType,
                                                             Rep.ReportAuthor,
                                                             Rep.ReportDescription,
                                                             Rep.ReportLocation,
                                                             Rep.ReportTime,
                                                             Rep.ReportLatitude,
                                                             Rep.ReportLongitude,
                                                             Rep.ReportAccuracy,
                                                             Rep.ReportDirection);

                reportObjectList.Add(reportObject);

                if (!(reportObject.ReportLatitude == "NA" || reportObject.ReportLatitude == "NA"))
                {
                    try
                    {
                        AddToMap(reportObject);
                    }
                    catch (Exception) { }
                }

                image.Height = 110;
                image.Width = 175;
                ImageView.Content = image;

                ReportView.Content = reportSP;

                ImageView.AddHandler(UIElement.TappedEvent, new TappedEventHandler(ImageSelected), true);
                ReportView.AddHandler(UIElement.TappedEvent, new TappedEventHandler(ReportSelected), true);

                listSP.Children.Add(ReportView);
                listSP.Children.Add(ImageView);

                ReportsListView.Items.Add(listSP);
            }
            UnLockControls();
        }
예제 #16
0
        /// <summary>
        /// Returns a Windows brush from the NGraphics brush
        /// </summary>
        /// <param name="fromBrush"></param>
        /// <returns></returns>
        private Windows.UI.Xaml.Media.Brush GetBrush(NGraphics.Brush fromBrush)
        {
            var sb = fromBrush as SolidBrush;

            if (sb != null)
            {
                // Solid brush
                return(new SolidColorBrush(new Windows.UI.Color {
                    A = sb.Color.A, R = sb.Color.R, G = sb.Color.G, B = sb.Color.B
                }));
            }

            var lb = fromBrush as NGraphics.LinearGradientBrush;

            if (lb != null)
            {
                // Linear gradient
                var gradStops = new GradientStopCollection();
                var n         = lb.Stops.Count;
                if (n >= 2)
                {
                    var locs  = new float[n];
                    var comps = new int[n];
                    for (var i = 0; i < n; i++)
                    {
                        var s = lb.Stops[i];
                        gradStops.Add(new Windows.UI.Xaml.Media.GradientStop
                        {
                            Color = new Windows.UI.Color {
                                A = s.Color.A,
                                R = s.Color.R,
                                B = s.Color.B,
                                G = s.Color.G,
                            },
                            Offset = s.Offset,
                        });
                    }
                }

                var grad = new Windows.UI.Xaml.Media.LinearGradientBrush(gradStops, 90);
                return(grad);
            }

            var rb = fromBrush as NGraphics.RadialGradientBrush;

            if (rb != null)
            {
                // Radial gradient
                throw new NotSupportedException("RadialGradientBrush is not supported for Windws Store Apps.");
                //var grad = new Windows.UI.Xaml.Media.RadialGradientBrush();
                //var n = rb.Stops.Count;
                //if (n >= 2)
                //{
                //    var locs = new float[n];
                //    var comps = new int[n];
                //    for (var i = 0; i < n; i++)
                //    {
                //        var s = rb.Stops[i];
                //        grad.GradientStops.Add(new Windows.UI.Xaml.Media.GradientStop
                //        {
                //            Color = new Windows.UI.Color
                //            {
                //                A = s.Color.A,
                //                R = s.Color.R,
                //                B = s.Color.B,
                //                G = s.Color.G,
                //            },
                //            Offset = s.Offset,
                //        });
                //    }
                //}
                //return grad;
            }

            return(null);
        }
        public async void SetGradient(LinearGradientBrush gradient)
        {
            GradientVisual = Compositor.CreateChildSprite(Element);
            var size = await Element.GetSize();

            ChildContainerVisual = Compositor.CreateChildContainer(Element);
            ChildContainerVisual.Children.InsertAtTop(GradientVisual);

            GradientVisual.Size = size;

            //To implement LinearGradientCompositionBrush

        }
 public void setBrushPath(String path)
 {
     this._brush = null;
     this._brushPath = path;
     this.OnPropertyChanged("Brush");
 }
        private void InitializeBrush(LinearGradientBrush br)
        {
            if (br == null)
                throw new ArgumentNullException("br");

            //set start and end interpolators
            double start = br.StartPoint.X;
            double end = br.EndPoint.X;

            if (br.GradientStops.Count < 2)
            {
                throw new Exception("2 Gradiant Stops must exist");
            }

            SolidColorBrushInterpolator startInterpolator = new SolidColorBrushInterpolator();
            startInterpolator.DataMinimum = start;
            startInterpolator.DataMaximum = br.GradientStops[1].Offset;
            startInterpolator.From = br.GradientStops[0].Color;
            startInterpolator.To = br.GradientStops[1].Color;
            interpolators.Add(startInterpolator);

            for (int i = 1; i < br.GradientStops.Count - 1; i++)
            {
                SolidColorBrushInterpolator inter = new SolidColorBrushInterpolator();
                inter.DataMinimum = br.GradientStops[i].Offset;
                inter.DataMaximum = br.GradientStops[i + 1].Offset;
                inter.From = br.GradientStops[i].Color;
                inter.To = br.GradientStops[i + 1].Color;
                interpolators.Add(inter);
            }
        }
 public static void SetGradient(UIElement element, LinearGradientBrush value)
 {
     element.SetValue(Gradientroperty, value);
 }
예제 #21
0
        public object ConvertToNative(Brush brush, object context)
        {
            winMedia.Brush winBrush = null;

            // SolidColorBrush
            if (brush is SolidColorBrush)
            {
                SolidColorBrush xamBrush = brush as SolidColorBrush;

                winBrush = new winMedia.SolidColorBrush
                {
                    Color = ConvertColor(xamBrush.Color)
                };
            }

            // LinearGradientBrush
            else if (brush is LinearGradientBrush)
            {
                LinearGradientBrush xamBrush = brush as LinearGradientBrush;

                winBrush = new winMedia.LinearGradientBrush
                {
                    StartPoint   = ConvertPoint(xamBrush.StartPoint),
                    EndPoint     = ConvertPoint(xamBrush.EndPoint),
                    SpreadMethod = ConvertGradientSpread(xamBrush.SpreadMethod)
                };

                foreach (GradientStop xamGradientStop in xamBrush.GradientStops)
                {
                    winMedia.GradientStop winGradientStop = new winMedia.GradientStop
                    {
                        Color  = ConvertColor(xamGradientStop.Color),
                        Offset = xamGradientStop.Offset
                    };

                    (winBrush as winMedia.LinearGradientBrush).GradientStops.Add(winGradientStop);
                }
            }

            else if (brush is ImageBrush)
            {
                ImageBrush xamBrush = brush as ImageBrush;

                winBrush = new winMedia.ImageBrush
                {
                    Stretch    = (winMedia.Stretch)(int) xamBrush.Stretch,
                    AlignmentX = (winMedia.AlignmentX)(int) xamBrush.AlignmentX,
                    AlignmentY = (winMedia.AlignmentY)(int) xamBrush.AlignmentY,
                };

                ImageSource xamImageSource = (brush as ImageBrush).ImageSource;

                if (xamImageSource != null)
                {
                    IImageSourceHandler handler = null;

                    if (xamImageSource.GetType() == typeof(FileImageSource))
                    {
                        handler = new FileImageSourceHandler();
                    }
                    else if (xamImageSource.GetType() == typeof(StreamImageSource))
                    {
                        handler = new StreamImageSourceHandler();
                    }
                    else if (xamImageSource.GetType() == typeof(UriImageSource))
                    {
                        handler = new UriImageSourceHandler();
                    }

                    if (handler != null)
                    {
                        Task <winMedia.ImageSource> winImageSourceTask = handler.LoadImageAsync(xamImageSource);

                        winImageSourceTask.ContinueWith((task) =>
                        {
                            winFound.IAsyncAction asyncAction = winBrush.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                (winBrush as winMedia.ImageBrush).ImageSource = task.Result;
                            });
                        });
                    }
                }
            }

            if (winBrush != null)
            {
                winBrush.Transform = brush.Transform?.GetNativeObject() as winMedia.MatrixTransform;

                // TODO: RelativeTransform and Opacity
            }

            return(winBrush);
        }
예제 #22
0
		private static void OnRateChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			var uc = obj as StarRating;
			if (uc != null && e.NewValue != e.OldValue)
			{
				double value = Convert.ToDouble(e.NewValue);

				uc.star_1.Fill = new SolidColorBrush(Colors.Gray);
				uc.star_2.Fill = new SolidColorBrush(Colors.Gray);
				uc.star_3.Fill = new SolidColorBrush(Colors.Gray);
				uc.star_4.Fill = new SolidColorBrush(Colors.Gray);
				uc.star_5.Fill = new SolidColorBrush(Colors.Gray);

				if (value == 0) return;

				double floorValue = Math.Floor(value);
				double realPart = value - floorValue;

				LinearGradientBrush gradient = new LinearGradientBrush();
				gradient.StartPoint = new Point(0.5, 0);
				gradient.EndPoint = new Point(1, 0);

				GradientStop first = new GradientStop();
				first.Color = Colors.Yellow;
				first.Offset = realPart;

				GradientStop second = new GradientStop();
				second.Color = Colors.Gray;
				second.Offset = realPart;

				gradient.GradientStops.Add(first);
				gradient.GradientStops.Add(second);

				if (value > 0 && value < 1)
				{
					uc.star_1.Fill = gradient;
					return;
				}

				if (value > 1 && value < 2)
				{
					uc.star_1.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_2.Fill = gradient;
					return;
				}

				if (value > 2 && value < 3)
				{
					uc.star_1.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_2.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_3.Fill = gradient;
					return;
				}

				if (value > 3 && value < 4)
				{
					uc.star_1.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_2.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_3.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_4.Fill = gradient;
					return;
				}

				if (value > 4 && value < 5)
				{
					uc.star_1.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_2.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_3.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_4.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_5.Fill = gradient;
					return;
				}
				else {
					uc.star_1.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_2.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_3.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_4.Fill = new SolidColorBrush(Colors.Yellow);
					uc.star_5.Fill = new SolidColorBrush(Colors.Yellow);
				}
			}
		}