private void RenderUI()
        {
            // get the layout base (a canvas here)
            _layoutRoot = (Grid)this.GetTemplateChild("LayoutRoot");


            // if we can't get the layout root, we can't do anything
            if (null == _layoutRoot)
            {
                return;
            }

            // update the grid
            _layoutRoot.Name = "AppSelectorGrid";



            // must construct additional columns or rows based on orientation and number
            // keep 1.0 so it creates a ratio (double) for the width/height definitions
            // coloring book will pass in image pairs, otherwise its a regular URI count from a normal app selector
            int iButtonCount = this.ImagePairs.Count > 0 ? this.ImagePairs.Count + 1: URIs.Count;

            double ratio = 1.0 / iButtonCount;

            if (this.MainOrientation == Orientation.Horizontal)
            {
                _layoutRoot.ColumnSpacing = WIDTH_GRID_COLUMNSPACING;
                _layoutRoot.RowDefinitions.Add(new RowDefinition());
                for (int i = 0; i < iButtonCount; i++)
                {
                    _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = new GridLength(ratio, GridUnitType.Star)
                    });
                }
            }
            else
            {
                //_layoutRoot.RowSpacing = (!IsListView ? WIDTH_GRID_ROWSPACING: 0);
                _layoutRoot.RowSpacing = WIDTH_GRID_ROWSPACING;
                _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
                for (int i = 0; i < iButtonCount; i++)
                {
                    _layoutRoot.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(ratio, GridUnitType.Star)
                    });
                }
            }

            // create the button style
            //if (IsListView)
            //{
            //    _buttonStyle = StyleHelper.GetApplicationStyle("ListViewButton");
            //}
            //else
            //{
            _buttonStyle = StyleHelper.GetApplicationStyle("AppSelectorButton");
            //}

            // JN loop this area to create images and buttons based on list
            int index = 0;

            if (this.ImagePairs.Count != 0)
            {// hubris! dont add clearbutton image pair unless it has a value. should only have a value on colorbook
                if (this.ClearButtonImagePair != null)
                {
                    GenerateButton(this.ClearButtonImagePair, 0, 0);
                    index = 1;
                }
                else
                {
                    index = 0;
                }

                for (int i = 0; i < this.ImagePairs.Count; i++, index++)
                {
                    GenerateButton(this.ImagePairs[i], i, index);
                }
            }
            else
            {
                for (int i = 0; i < this.URIs.Count; i++)
                {
                    GenerateButton(this.URIs[i], i);
                }
            }


            if (this.ShowSelectedLine)
            {
                selectedLine.StrokeThickness = 5;
                double LineRightMargin  = StyleHelper.GetApplicationDouble("AppSelectorLineBottomMargin");
                double LineBottomMargin = StyleHelper.GetApplicationDouble("AppSelectorLineBottomMargin");

                if (this.MainOrientation == Orientation.Vertical)
                {
                    selectedLine.X1 = -LineRightMargin;
                    selectedLine.Y1 = VERTICAL_LINE_OFFSET;

                    selectedLine.X2 = -LineRightMargin;
                    selectedLine.Y2 = this.ButtonHeight + VERTICAL_LINE_OFFSET;
                }
                if (this.MainOrientation == Orientation.Horizontal)
                {
                    selectedLine.X1 = 3;
                    selectedLine.Y1 = this.ButtonHeight + 5 + LineBottomMargin;

                    selectedLine.X2 = this.ButtonWidth + 4;// border thickness for some reason 2 on both sides
                    selectedLine.Y2 = this.ButtonHeight + 5 + LineBottomMargin;
                }

                SolidColorBrush SelectedLineColor = RadiatingButton.GetSolidColorBrush("#FF0078D4");

                selectedLine.Stroke = SelectedLineColor;
                selectedLine.Fill   = SelectedLineColor;
                _layoutRoot.Children.Add(selectedLine);

                this.SelectedButton = this.Buttons[0];// set the first button as the selected button for line moving

                // need sine easing
                SineEase sineEaseIn = new SineEase()
                {
                    EasingMode = EasingMode.EaseIn
                };
                // set this once here and forget it.
                this.selectedLine.RenderTransform = this.translateTransform;
                Duration duration = new Duration(new TimeSpan(0, 0, 0, 0, 400));
                daAnimation = new DoubleAnimation()
                {
                    Duration       = duration,
                    EasingFunction = sineEaseIn
                };

                this.storyboard.Children.Add(daAnimation);
                Storyboard.SetTarget(daAnimation, this.translateTransform);
                if (this.MainOrientation == Orientation.Horizontal)
                {
                    Storyboard.SetTargetProperty(daAnimation, "X");
                }
                if (this.MainOrientation == Orientation.Vertical)
                {
                    Storyboard.SetTargetProperty(daAnimation, "Y");
                }
            }

            // set up animations
            _storyboardFadeIn  = AnimationHelper.CreateEasingAnimation(_layoutRoot, "Opacity", 0.0, 0.0, 1.0, this.DurationInMilliseconds, this.StaggerDelayInMilliseconds, false, false, new RepeatBehavior(1d));
            _storyboardFadeOut = AnimationHelper.CreateEasingAnimation(_layoutRoot, "Opacity", 1.0, 1.0, 0.0, this.DurationInMilliseconds, this.StaggerDelayInMilliseconds, false, false, new RepeatBehavior(1d));

            this.UpdateUI();
        }
        private void RenderUI()
        {
            _layoutRoot = (Canvas)this.GetTemplateChild("LayoutRoot");
            if (null == _layoutRoot)
            {
                return;
            }

            // get sizes for everything
            double _canvasWidth  = StyleHelper.GetApplicationDouble("CanvasWidth");
            double _canvasHeight = StyleHelper.GetApplicationDouble("CanvasHeight");

            double _startImageWidth  = StyleHelper.GetApplicationDouble("PinchZoomImageWidth");
            double _startImageHeight = StyleHelper.GetApplicationDouble("PinchZoomImageHeight");

            double _radiatingButtonRadius   = StyleHelper.GetApplicationDouble(LayoutSizes.RadiatingButtonEllipseRadius);
            double _closeIconHeight         = StyleHelper.GetApplicationDouble(LayoutSizes.TryItIconHeight) / 2;
            double _closeEllipseTopMargin   = StyleHelper.GetApplicationDouble("PinchTopMargin");
            double _closeEllipseRightMargin = StyleHelper.GetApplicationDouble("PinchSideMargin");

            double _ellipseGridCanvasSetLeft = _canvasWidth - _closeEllipseRightMargin - _radiatingButtonRadius;

            // create the scroll viewer
            _viewer = new ScrollViewer
            {
                ZoomMode                      = ZoomMode.Enabled,
                Width                         = _canvasWidth,
                Height                        = _canvasHeight,
                MinZoomFactor                 = 1,
                MaxZoomFactor                 = 4,
                HorizontalScrollMode          = ScrollMode.Enabled,
                VerticalScrollMode            = ScrollMode.Enabled,
                HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
                VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden
            };

            // create the image for zooming
            _pinch_image = new ImageEx
            {
                Name                = this.Name + "ZoomImage",
                ImageSource         = ImageUri,
                ImageWidth          = _startImageWidth, //account for left and right margins
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };

            // add the image to the scroll viewer
            _viewer.Content = _pinch_image;

            // add manipulation events to viewer
            _viewer.ViewChanging += HandleZoomChanging;

            // add the scrollviewer to the root
            _layoutRoot.Children.Add(_viewer);

            // create grid for the close element if none exists
            if (null == _closeGrid)
            {
                _closeGrid = new Grid()
                {
                    Name       = this.Name + "closeGrid",
                    Visibility = Visibility.Collapsed
                };
            }

            // create the close button
            _closeEllipse = new Ellipse()
            {
                Name                = this.Name + "entranceEllipse",
                Width               = _radiatingButtonRadius,
                Height              = _radiatingButtonRadius,
                Fill                = new SolidColorBrush(Colors.White),
                Stroke              = RadiatingButton.GetSolidColorBrush("#FFD2D2D2"),
                StrokeThickness     = 2,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Margin              = new Thickness(0)
            };
            // add ellipse to the grid
            _closeGrid.Children.Add(_closeEllipse);

            // create the X image
            x_image = new ImageEx()
            {
                Name                = this.Name + "ImageX",
                ImageSource         = URI_X_IMAGE,
                ImageWidth          = _closeIconHeight,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Margin              = new Thickness(0)
            };

            // add the close image to the grid
            _closeGrid.Children.Add(x_image);

            // set canvas position for the close grid
            Canvas.SetLeft(_closeGrid, _ellipseGridCanvasSetLeft);
            Canvas.SetTop(_closeGrid, _closeEllipseTopMargin);

            // assign click handler
            _closeGrid.PointerPressed += HandleClick;

            // add the close button to the layout root
            _layoutRoot.Children.Add(_closeGrid);
        }
Exemple #3
0
        public ExperiencePopupViewModel()
        {
            closeEllipseTopMargin    = _closeEllipseTopMargin;
            ellipseGridCanvasSetLeft = _maxImageWidth - _closeEllipseRightMargin - _radiatingButtonRadius;
            radiatingButtonRadius    = _radiatingButtonRadius;
            closeIconHeight          = _closeIconHeight;
            ellipseStroke            = RadiatingButton.GetSolidColorBrush("#FFD2D2D2");

            this.appSelectorData.Add(new AppSelectorData()
            {
                Source_NotSelectedImage = URI_APPSELECTOR_COLOR_1,
                Source_SelectedImage    = URI_APPSELECTOR_COLOR_1_SELECTED
            });
            this.appSelectorImageURIs.Add(new AppSelectorImageURI()
            {
                URI   = URI_IMAGESELECTOR_IMAGE_1,
                Width = SELECTORIMAGE_IMAGEWIDTH
            });

            this.appSelectorData.Add(new AppSelectorData()
            {
                Source_NotSelectedImage = URI_APPSELECTOR_COLOR_2,
                Source_SelectedImage    = URI_APPSELECTOR_COLOR_2_SELECTED
            });
            this.appSelectorImageURIs.Add(new AppSelectorImageURI()
            {
                URI   = URI_IMAGESELECTOR_IMAGE_2,
                Width = SELECTORIMAGE_IMAGEWIDTH
            });

            this.appSelectorData.Add(new AppSelectorData()
            {
                Source_NotSelectedImage = URI_APPSELECTOR_COLOR_3,
                Source_SelectedImage    = URI_APPSELECTOR_COLOR_3_SELECTED
            });
            this.appSelectorImageURIs.Add(new AppSelectorImageURI()
            {
                URI   = URI_IMAGESELECTOR_IMAGE_3,
                Width = SELECTORIMAGE_IMAGEWIDTH
            });

            this.appSelectorData.Add(new AppSelectorData()
            {
                Source_NotSelectedImage = URI_APPSELECTOR_COLOR_4,
                Source_SelectedImage    = URI_APPSELECTOR_COLOR_4_SELECTED
            });
            this.appSelectorImageURIs.Add(new AppSelectorImageURI()
            {
                URI   = URI_IMAGESELECTOR_IMAGE_4,
                Width = SELECTORIMAGE_IMAGEWIDTH
            });

            this.appSelectorData.Add(new AppSelectorData()
            {
                Source_NotSelectedImage = URI_APPSELECTOR_COLOR_5,
                Source_SelectedImage    = URI_APPSELECTOR_COLOR_5_SELECTED
            });
            this.appSelectorImageURIs.Add(new AppSelectorImageURI()
            {
                URI   = URI_IMAGESELECTOR_IMAGE_5,
                Width = SELECTORIMAGE_IMAGEWIDTH
            });

            // get the localization service
            LocalizationService localizationService = SimpleIoc.Default.GetInstance <LocalizationService>();

            // if we got it
            if (null != localizationService)
            {
                // load ourself with values from the language file
                localizationService.LoadExperiencePopupViewModel(this);
            }
        }