/// <summary> /// /// </summary> /// <param name="textField"></param> /// <param name="isFirst">Whether this is the first top-level item on the surface.</param> /// <param name="isFirstGroup">Whether this is inside a group.</param> /// <param name="previousLineStyleIndex"></param> /// <param name="topMarginOffset"></param> /// <param name="needsImageMargin"></param> /// <param name="lineStyleIndex"></param> /// <returns></returns> public static TextBlock GenerateText( AdaptiveTextField textField, bool isFirst, bool isFirstGroup, int previousLineStyleIndex, double topMarginOffset, bool needsImageMargin, out int lineStyleIndex) { lineStyleIndex = -1; TextBlock spTextBlock = new TextBlock() { //Foreground = TextBlockBrush, Text = textField.Text, TextWrapping = DefaultTextWrapping }; // Get the text style info bool isSubtle; TextStyleInfo textStyleInfo = GetStyleIndex(textField.HintStyle, out isSubtle); // Set the XAML text style SetStyle(spTextBlock, textStyleInfo.XamlName); // If it's subtle if (isSubtle) { // Apply subtle opacity spTextBlock.Opacity = SubtleOpacity; } // Get the style index lineStyleIndex = textStyleInfo.Index; // Default top margin values for textblocks double topMargin; if (isFirst) { if (isFirstGroup) { topMargin = DefaultTypeRamp[lineStyleIndex].FirstGroupMargin - AdaptiveConstants.DefaultExternalMargin; } else { topMargin = topMarginOffset - DefaultTypeRamp[lineStyleIndex].TopOffset; } } else if (previousLineStyleIndex != -1) { topMargin = DefaultTypeRamp[previousLineStyleIndex].TopMarginValues[lineStyleIndex]; } else if (needsImageMargin) { topMargin = AdaptiveConstants.DefaultImageMargin; } else { topMargin = DefaultTypeRamp[0].TopMarginValues[lineStyleIndex]; } // Override if needed line height if (DefaultTypeRamp[lineStyleIndex].LineHeightOverride > 0.0) { spTextBlock.LineHeight = DefaultTypeRamp[lineStyleIndex].LineHeightOverride; } // Text wrapping if (textField.HintWrap.GetValueOrDefault(false)) { spTextBlock.TextWrapping = TextWrapping.Wrap; } // Max lines if (textField.HintMaxLines != null) { spTextBlock.MaxLines = textField.HintMaxLines.Value; } // Align switch (textField.HintAlign) { case Model.Enums.HintAlign.Center: spTextBlock.TextAlignment = TextAlignment.Center; break; case Model.Enums.HintAlign.Right: spTextBlock.TextAlignment = TextAlignment.Right; break; case Model.Enums.HintAlign.Left: default: spTextBlock.TextAlignment = TextAlignment.Left; break; } spTextBlock.OpticalMarginAlignment = DefaultOpticalMarginAlignment; spTextBlock.TextLineBounds = textStyleInfo.TextLineBounds; spTextBlock.TextTrimming = DefaultTextTrimming; // Min lines (default of HintMinLines is 1) spTextBlock.MinHeight = textField.HintMinLines.GetValueOrDefault(1) * DefaultTypeRamp[lineStyleIndex].MinLineHeight; // Margins Thickness margins = new Thickness(0, topMargin, 0, 0); spTextBlock.Margin = margins; return(spTextBlock); }
private void InitializeContent(IToast toastContent) { _currContent = toastContent; HasContent = false; TextBlockTitle.Text = ""; TextBlockTitle.MaxLines = 3; TextBlockTitle.TextWrapping = TextWrapping.WrapWholeWords; TextBlockBody.Text = ""; TextBlockBody.MaxLines = 3; TextBlockBody.TextWrapping = TextWrapping.WrapWholeWords; TextBlockBody2.Visibility = Visibility.Collapsed; TextBlockBody2.MaxLines = 3; TextBlockBody2.TextWrapping = TextWrapping.WrapWholeWords; StackPanelInlineImages.Children.Clear(); DefaultImageAppLogo.Visibility = Visibility.Visible; ImageAppLogo.Visibility = Visibility.Collapsed; CircleImageAppLogo.Visibility = Visibility.Collapsed; _elementsWithIds = new Dictionary <string, FrameworkElement>(); _currLaunch = ""; _currActivationType = ActivationType.Foreground; _buttons.Clear(); _buttons.Add(CreateButton("Launch", toastContent?.Launch, null, toastContent != null ? toastContent.ActivationType.GetValueOrDefault(ActivationType.Foreground) : ActivationType.Foreground, Scenario.Default)); if (toastContent != null) { _currLaunch = toastContent.Launch; _currActivationType = toastContent.ActivationType.GetValueOrDefault(ActivationType.Foreground); if (toastContent.Visual != null) { var visual = toastContent.Visual; AdaptiveBinding binding; if (toastContent.Context == NotificationType.Toast) { binding = visual.Bindings.FirstOrDefault(); } else { binding = visual.Bindings.FirstOrDefault(i => i.Template == Model.Enums.Template.ToastGeneric); } if (binding != null) { HasContent = true; var container = binding.Container; var texts = container.Children.OfType <AdaptiveTextField>().ToList(); List <AdaptiveImage> appLogoOverrides = null; List <AdaptiveImage> heroImages = new List <AdaptiveImage>(); var attributionTexts = container.Children.OfType <AdaptiveTextField>().Where(i => i.Placement == Model.Enums.TextPlacement.Attribution).ToList(); appLogoOverrides = new List <AdaptiveImage>(); // First pull out images with placements and attribution text for (int i = 0; i < container.Children.Count; i++) { var child = container.Children[i]; if (child is AdaptiveImage) { AdaptiveImage img = child as AdaptiveImage; switch (img.Placement) { case Model.Enums.Placement.AppLogoOverride: appLogoOverrides.Add(img); container.RemoveChildAt(i); i--; break; case Model.Enums.Placement.Hero: heroImages.Add(img); container.RemoveChildAt(i); i--; break; } } else if (child is AdaptiveTextField) { AdaptiveTextField txt = child as AdaptiveTextField; if (txt.Placement != Model.Enums.TextPlacement.Inline) { container.RemoveChildAt(i); i--; } } } // Assign hero if (heroImages.Any()) { ImageHero.Visibility = Visibility.Visible; ImageHeroBrush.ImageSource = ImageHelper.GetBitmap(heroImages.First().Src); } else { ImageHero.Visibility = Visibility.Collapsed; ImageHeroBrush.ImageSource = null; } texts = new List <AdaptiveTextField>(); // Pull out all texts for (int i = 0; i < container.Children.Count; i++) { var child = container.Children[i]; if (child is AdaptiveTextField && (child as AdaptiveTextField).Placement == Model.Enums.TextPlacement.Inline) { texts.Add(child as AdaptiveTextField); container.RemoveChildAt(i); i--; } } var titleText = texts.ElementAtOrDefault(0); if (titleText != null) { TextBlockTitle.Text = titleText.Text; var bodyTextLine1 = texts.ElementAtOrDefault(1); if (bodyTextLine1 != null) { TextBlockBody.Text = bodyTextLine1.Text; var bodyTextLine2 = texts.ElementAtOrDefault(2); if (bodyTextLine2 != null) { TextBlockBody2.Text = bodyTextLine2.Text; TextBlockBody2.Visibility = Visibility.Visible; } TextBlockBody.Visibility = Visibility.Visible; } else { TextBlockBody.Visibility = Visibility.Collapsed; } } else { TextBlockTitle.Text = Properties.DisplayName; TextBlockBody.Text = "New notification"; TextBlockBody.Visibility = Visibility.Visible; } var images = container.Children.OfType <AdaptiveImage>().ToList(); if (appLogoOverrides == null) { appLogoOverrides = images.Where(i => i.Placement == Model.Enums.Placement.AppLogoOverride).ToList(); } var appLogoOverride = appLogoOverrides.FirstOrDefault(); if (appLogoOverride != null) { DefaultImageAppLogo.Visibility = Visibility.Collapsed; var source = ImageHelper.GetBitmap(appLogoOverride.Src); if (appLogoOverride.HintCrop == Model.Enums.HintCrop.Circle) { CircleImageAppLogo.Source = source; CircleImageAppLogo.Visibility = Visibility.Visible; } else { ImageAppLogo.Source = source; ImageAppLogo.Visibility = Visibility.Visible; } } foreach (var image in images.Where(i => i.Placement == Model.Enums.Placement.Inline)) { var uiImage = new Image() { Source = ImageHelper.GetBitmap(image.Src), MaxHeight = 100, Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0, 0, 0, 6) }; StackPanelInlineImages.Children.Add(uiImage); } // Attribution if (toastContent.SupportedFeatures.RS1_Style_Toasts) { if (attributionTexts.Any()) { TextBlockAttributionSeparationDot.Visibility = Visibility.Visible; TextBlockAttributionSecondPart.Visibility = Visibility.Visible; TextBlockAttributionSecondPart.Text = attributionTexts.First().Text; } else { TextBlockAttributionSeparationDot.Visibility = Visibility.Collapsed; TextBlockAttributionSecondPart.Visibility = Visibility.Collapsed; } } } } if (toastContent.Actions != null) { var actions = toastContent.Actions; if (actions.HintSystemCommands == Model.Enums.HintSystemCommands.SnoozeAndDismiss) { //AddInput(CreateComboBox("systemSnoozeSelection", null, new Selection[] //{ // new Selection(NotificationType.Toast, CurrFeatureSet) // { // Content = "5 minutes", // Id = "5" // }, // new Selection(NotificationType.Toast, CurrFeatureSet) // { // Content = "9 minutes", // Id = "9" // }, // new Selection(NotificationType.Toast, CurrFeatureSet) // { // Content = "10 minutes", // Id = "10" // }, // new Selection(NotificationType.Toast, CurrFeatureSet) // { // Content = "1 hour", // Id = "60" // }, // new Selection(NotificationType.Toast, CurrFeatureSet) // { // Content = "4 hours", // Id = "240" // }, // new Selection(NotificationType.Toast, CurrFeatureSet) // { // Content = "1 day", // Id = "1440" // } //}, "9", true)); AddButton(CreateButton("Snooze", "snooze", null, ActivationType.System, toastContent.Scenario)); AddButton(CreateButton("Dismiss", "dismiss", null, ActivationType.System, toastContent.Scenario)); } else { List <Model.BaseElements.Action> actionElements = actions.ActionElements.ToList(); if (toastContent.SupportedFeatures.RS1_Style_Toasts) { actionElements.RemoveAll(i => i.Placement != Model.Enums.ActionPlacement.Inline); } // Initialize inputs foreach (var i in actions.Inputs) { ListViewButton button; switch (i.Type) { case Model.BaseElements.InputType.Text: button = new TextBoxButton(i); break; case Model.BaseElements.InputType.Selection: button = new SelectionButton(i); break; default: throw new NotImplementedException(); } AddButton(button); } // Initialize buttons foreach (var a in actionElements) { ListViewButton uiButton = CreateButton(a.Content, a.Arguments, a.ImageUri, a.ActivationType, toastContent.Scenario); //AssignId(uiButton, a.Id); //if (!a.HintVisible) // uiButton.Visibility = Visibility.Collapsed; AddButton(uiButton); } } } } ListViewButtons.SelectedIndex = 0; }