private void RenderUI() { // get the layoutroot _layoutRoot = (Border)this.GetTemplateChild("LayoutRoot"); if (null == _layoutRoot) { return; } // clear its children _layoutRoot.Child = null; // calculate element widths double gridWidth = this.Width; // calculate rows GridLength headlineRowHeight = (String.IsNullOrWhiteSpace(this.Headline)) ? new GridLength(0) : GridLength.Auto; GridLength ledeRowHeight = (String.IsNullOrWhiteSpace(this.Lede)) ? new GridLength(0) : new GridLength(1.0, GridUnitType.Star); double rowSpacing = (String.IsNullOrWhiteSpace(this.Headline) || String.IsNullOrWhiteSpace(this.Lede)) || !this.IsRowSpacingActive ? 0d : 10d; // create the grid _layoutGrid = new Grid() { Name = "LayoutGrid", Width = gridWidth, RowSpacing = rowSpacing }; _layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = headlineRowHeight }); _layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = ledeRowHeight }); _layoutGrid.ColumnDefinitions.Add(new ColumnDefinition()); // add it to the root _layoutRoot.Child = _layoutGrid; // if we have a headline if (!String.IsNullOrWhiteSpace(this.Headline)) { // create headline // ================= _headline = new TextBlockEx() { Name = "Headline", TextAlignment = this.HeaderAlignment, TextWrapping = TextWrapping.WrapWholeWords, Width = gridWidth, TextStyle = this.HeadlineStyle, TranslateDirection = this.Direction(), Opacity = this.HeadlineOpacity }; Grid.SetRow(_headline, 0); Grid.SetColumn(_headline, 0); // set headline binding _headline.SetBinding(TextBlockEx.TextProperty, new Binding() { Source = this, Path = new PropertyPath("Headline"), Mode = BindingMode.OneWay }); // add to the grid _layoutGrid.Children.Add(_headline); //// update layout //this.UpdateLayout(); } // if we have a lede if (!String.IsNullOrWhiteSpace(this.Lede)) { double _ledeWidth = this.LedeWidth > 0 ? LedeWidth : gridWidth; // create lede // ================= _lede = new TextBlockEx() { Name = "Lede", TextAlignment = this.HeaderAlignment, TextWrapping = TextWrapping.WrapWholeWords, Width = _ledeWidth, TextStyle = this.LedeStyle, HorizontalAlignment = this.HorizontalAlignment, TranslateDirection = this.Direction(), Opacity = this.LedeOpacity }; Grid.SetRow(_lede, 1); Grid.SetColumn(_lede, 0); // if there's a call to action if ((!String.IsNullOrWhiteSpace(this.CTAText)) && (null != this.CTAUri)) { // get style for the cta run Style ledeStyle = StyleHelper.GetApplicationStyle(this.LedeStyle); Style ctaStyle = StyleHelper.GetApplicationStyle(this.CTATextStyle); // create the lede _ledeRun = new Run() { Text = this.Lede + CHAR_NBSPACE + CHAR_NBSPACE }; StyleHelper.SetRunStyleFromStyle(_ledeRun, ledeStyle); _lede.AddInline(_ledeRun); // create the hyperlink _ledeCTALink = new Hyperlink() { //NavigateUri = (this.CTAUri) // can't do this because we need to catch the Click event ourselves }; // create the text for the hyperlink _ledeCTAText = new Run() { Text = this.CTAText.ToUpper() }; StyleHelper.SetRunStyleFromStyle(_ledeCTAText, ctaStyle); _ledeCTALink.Inlines.Add(_ledeCTAText); _lede.AddInline(_ledeCTALink); // add the click handler for the link _ledeCTALink.Click += CTALink_Click; } else { // no CTA, so this is simple text; set lede binding _lede.SetBinding(TextBlockEx.TextProperty, new Binding() { Source = this, Path = new PropertyPath("Lede"), Mode = BindingMode.OneWay }); } // add to the grid _layoutGrid.Children.Add(_lede); } }
private void RenderUI() { // get the layoutroot _layoutRoot = (Grid)this.GetTemplateChild("LayoutRoot"); if (null == _layoutRoot) { return; } // clear any children _layoutRoot.Children.Clear(); // get our sizes double arrowWidth = StyleHelper.GetApplicationDouble(LayoutSizes.SwipeToContinueArrowWidth); double spacer = StyleHelper.GetApplicationDouble(LayoutSizes.SwipeToContinueSpacer); // set up grid _layoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(arrowWidth) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(arrowWidth) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(arrowWidth) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(arrowWidth) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(arrowWidth) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(spacer) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); // add a translate transform to the layout root _translateGrid = new TranslateTransform() { X = 0 }; _layoutRoot.RenderTransform = _translateGrid; // manipulation mode _layoutRoot.ManipulationMode = ManipulationModes.TranslateRailsX; // attach to the manipulation events _layoutRoot.ManipulationStarted += Grid_ManipulationStarted; _layoutRoot.ManipulationDelta += Grid_ManipulationDelta; _layoutRoot.ManipulationCompleted += Grid_ManipulationCompleted; // create arrow bitmap _arrowBitmapImage = new BitmapImage() { UriSource = new Uri(ARROW_URI), DecodePixelWidth = (int)arrowWidth, }; // create arrows _arrowLeftmost = new Image() { Width = arrowWidth, Opacity = 0.0, Source = _arrowBitmapImage }; Grid.SetRow(_arrowLeftmost, 0); Grid.SetColumn(_arrowLeftmost, 0); _layoutRoot.Children.Add(_arrowLeftmost); _arrowLeft = new Image() { Width = arrowWidth, Opacity = 0.0, Source = _arrowBitmapImage }; Grid.SetRow(_arrowLeft, 0); Grid.SetColumn(_arrowLeft, 1); _layoutRoot.Children.Add(_arrowLeft); _arrowMiddle = new Image() { Width = arrowWidth, Opacity = 0.0, Source = _arrowBitmapImage }; Grid.SetRow(_arrowMiddle, 0); Grid.SetColumn(_arrowMiddle, 2); _layoutRoot.Children.Add(_arrowMiddle); _arrowRight = new Image() { Width = arrowWidth, Opacity = 0.0, Source = _arrowBitmapImage }; Grid.SetRow(_arrowRight, 0); Grid.SetColumn(_arrowRight, 3); _layoutRoot.Children.Add(_arrowRight); _arrowRightmost = new Image() { Width = arrowWidth, Opacity = 0.0, Source = _arrowBitmapImage }; Grid.SetRow(_arrowRightmost, 0); Grid.SetColumn(_arrowRightmost, 4); _layoutRoot.Children.Add(_arrowRightmost); // create textblock _textSwipe = new TextBlockEx() { TextStyle = TextStyles.Swipe, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Opacity = 0.0, }; _textSwipe.SetBinding(TextBlockEx.TextProperty, new Binding() { Source = this, Path = new PropertyPath("SwipeText"), Mode = BindingMode.OneWay }); Grid.SetRow(_textSwipe, 0); Grid.SetColumn(_textSwipe, 6); _layoutRoot.Children.Add(_textSwipe); // animation calculations double staggerDelayIn = ANIM_STAGGER_TEXT; // text fade in _storyboardText = AnimationHelper.CreateEasingAnimation(_textSwipe, "(UIElement.Opacity)", 0.0, 0.0, 1.0, null, null, ANIM_FADEIN_TEXT, staggerDelayIn, false, false, new RepeatBehavior(1d)); staggerDelayIn += ANIM_FADEIN_TEXT + ANIM_STAGGER_FIRSTARROW; // right most arrow fade in _storyboardRightmostArrow = AnimationHelper.CreateEasingAnimation(_arrowRightmost, "(UIElement.Opacity)", 0.0, 0.0, 1.0, null, null, ANIM_FADEIN_ARROW, staggerDelayIn, false, false, new RepeatBehavior(1d)); staggerDelayIn += ANIM_FADEIN_ARROW + ANIM_STAGGER_NEXTARROWS + ANIM_REST_ARROW; // right arrow fade in _storyboardRightArrow = AnimationHelper.CreateEasingAnimation(_arrowRight, "(UIElement.Opacity)", 0.0, 0.0, 1.0, null, null, ANIM_FADEIN_ARROW, staggerDelayIn, false, false, new RepeatBehavior(1d)); staggerDelayIn += ANIM_FADEIN_ARROW + ANIM_STAGGER_NEXTARROWS + ANIM_REST_ARROW; // middle arrow fade in _storyboardMiddleArrow = AnimationHelper.CreateEasingAnimation(_arrowMiddle, "(UIElement.Opacity)", 0.0, 0.0, 1.0, null, null, ANIM_FADEIN_ARROW, staggerDelayIn, false, false, new RepeatBehavior(1d)); staggerDelayIn += ANIM_FADEIN_ARROW + ANIM_STAGGER_NEXTARROWS + ANIM_REST_ARROW; // left arrow fade in _storyboardLeftArrow = AnimationHelper.CreateEasingAnimation(_arrowLeft, "(UIElement.Opacity)", 0.0, 0.0, 1.0, null, null, ANIM_FADEIN_ARROW, staggerDelayIn, false, false, new RepeatBehavior(1d)); staggerDelayIn += ANIM_FADEIN_ARROW + ANIM_STAGGER_NEXTARROWS + ANIM_REST_ARROW; // left most arrow fade in _storyboardLeftmostArrow = AnimationHelper.CreateEasingAnimation(_arrowLeftmost, "(UIElement.Opacity)", 0.0, 0.0, 1.0, null, null, ANIM_FADEIN_ARROW, staggerDelayIn, false, false, new RepeatBehavior(1d)); staggerDelayIn += ANIM_FADEIN_ARROW + ANIM_STAGGER_NEXTARROWS + ANIM_REST_ARROW; //// set up fade animations //_storyboardFadeIn = AnimationHelper.CreateStandardEasingAnimation(_layoutRoot, "Opacity", 0.0, 0.0, 1.0, 100d, 0d, false, false, new RepeatBehavior(1d)); //_storyboardFadeOut = AnimationHelper.CreateStandardEasingAnimation(_layoutRoot, "Opacity", 1.0, 1.0, 0.0, 100d, 0d, false, false, new RepeatBehavior(1d)); }
private void RenderUI() { // get the layoutroot _layoutRoot = (Grid)this.GetTemplateChild("LayoutRoot"); if (null == _layoutRoot) { return; } // clear any children _layoutRoot.Children.Clear(); // get ellipse size double ellipseSize = StyleHelper.GetApplicationDouble(LayoutSizes.SwipeLeftEllipseRadius); // set up grid _layoutRoot.Width = WIDTH_CONTROL; _layoutRoot.RowSpacing = StyleHelper.GetApplicationDouble(LayoutSizes.SwipeLeftSpacer); _layoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(ellipseSize) }); _layoutRoot.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1.0, GridUnitType.Auto) }); _layoutRoot.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1.0, GridUnitType.Star) }); // test //TestHelper.AddGridCellBorders(_layoutRoot, 2, 1, Colors.DeepSkyBlue); // create textblock _textSwipe = new TextBlockEx() { Name = "SwipeText", TextStyle = TextStyles.Swipe, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; _textSwipe.SetBinding(TextBlockEx.TextProperty, new Binding() { Source = this, Path = new PropertyPath("SwipeText"), Mode = BindingMode.OneWay }); Grid.SetRow(_textSwipe, 1); Grid.SetColumn(_textSwipe, 0); _layoutRoot.Children.Add(_textSwipe); // create the ellipse _ellipseSwipe = new Ellipse() { Width = ellipseSize, Height = ellipseSize, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, Stroke = new SolidColorBrush(Colors.White), Fill = new SolidColorBrush(Colors.White), Opacity = 0.0 }; Grid.SetRow(_ellipseSwipe, 0); Grid.SetColumn(_ellipseSwipe, 0); _layoutRoot.Children.Add(_ellipseSwipe); // add a translate transform to the ellipse _translateEllipse = new TranslateTransform() { X = 0 }; _ellipseSwipe.RenderTransform = _translateEllipse; // set up control fades _storyboardFadeIn = AnimationHelper.CreateEasingAnimation(_layoutRoot, "Opacity", 0.0, 0.0, 1.0, this.DurationInMilliseconds, this.StaggerDelayInMilliseconds + ANIM_STAGGER_TEXT_FADEIN, false, false, new RepeatBehavior(1)); _storyboardFadeOut = AnimationHelper.CreateEasingAnimation(_layoutRoot, "Opacity", 0.0, 1.0, 0.0, this.DurationInMilliseconds, this.StaggerDelayInMilliseconds + ANIM_STAGGER_TEXT_FADEOUT, false, false, new RepeatBehavior(1)); // set up ellipse fades _storyboardEllipseFadeIn = AnimationHelper.CreateEasingAnimationWithNotify(_ellipseSwipe, this.FadeIn_Complete, "Opacity", 0.0, 0.0, 1.0, null, null, ANIM_DURATION_ELLIPSE_FADE, this.StaggerDelayInMilliseconds + ANIM_STAGGER_ELLIPSE_FADEIN, false, false, new RepeatBehavior(1)); _storyboardEllipseFadeOut = AnimationHelper.CreateEasingAnimation(_ellipseSwipe, "Opacity", 0.0, 1.0, 0.0, ANIM_DURATION_ELLIPSE_FADE, 0d, false, false, new RepeatBehavior(1)); // fade out original stagger: this.StaggerDelayInMilliseconds + ANIM_STAGGER_ELLIPSE_FADEOUT QuinticEase quinticEase = new QuinticEase() { EasingMode = EasingMode.EaseInOut }; // set up ellipse move _storyboardEllipseMove = AnimationHelper.CreateEasingAnimationWithNotify(_ellipseSwipe, this.Move_Complete, "(Ellipse.RenderTransform).(TranslateTransform.X)", 0.0, 0.0, -1 * WIDTH_CONTROL + ellipseSize, quinticEase, quinticEase, ANIM_DURATION_ELLIPSE_MOVE, 0d, false, false, new RepeatBehavior(1)); // move original stagger: this.StaggerDelayInMilliseconds + ANIM_STAGGER_ELLIPSE_MOVE }