示例#1
0
        /// <summary>
        /// This should only be called once. For new tile notification content, create a new instance of this element.
        /// </summary>
        /// <param name="tileSize"></param>
        /// <param name="tilePixelSize"></param>
        /// <param name="visualElements"></param>
        /// <param name="isBrandingVisible"></param>
        /// <param name="binding"></param>
        public void Initialize(TileSize tileSize, PreviewTileVisualElements visualElements, bool isBrandingVisible, JsonTileCardContent content, JsonParseTileResult result)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            _tileSize = tileSize;

            // Set the background color
            TileContentContainer.Background = new SolidColorBrush(visualElements.BackgroundColor);

            UsingPeek = false;

            {
                // Calculate the tile margin
                Thickness margin = new Thickness(GetExternalMargin());

                if (isBrandingVisible)
                {
                    switch (tileSize)
                    {
                    case TileSize.Small:
                        margin.Bottom = BRANDING_HEIGHT - 4;
                        break;

                    default:
                        margin.Bottom = BRANDING_HEIGHT;
                        break;
                    }
                }

                // Render the adaptive
                if (content.Content != null && content.Content.Length > 0)
                {
                    string finalCardJson;
                    var    adaptiveVisual = CardRenderer.RenderBody(content.Content, content.BaseUrl, null, null, out finalCardJson);
                    if (adaptiveVisual != null && (adaptiveVisual as Panel).Children.Count > 0)
                    {
                        TileContent.Child = new Border()
                        {
                            Child   = adaptiveVisual,
                            Padding = new Thickness(margin.Left - 1, margin.Top - 4, margin.Right - 1, margin.Bottom)
                        };
                    }
                    else
                    {
                        result?.Errors.Add(new ParseError(ParseErrorType.ErrorButRenderAllowed, "Failed to render adaptive content."));
                    }
                }


                // Background image
                var backgroundImage = content.BackgroundImage;
                var peekImage       = content.PeekContent?.BackgroundImage;

                // If we don't support both peek and background, then just peek is used
                //if (!binding.SupportedFeatures.BackgroundAndPeekImage && backgroundImage != null && peekImage != null)
                //    backgroundImage = null;


                // Calculate overlays
                double backgroundOverlay = 0;

                if (backgroundImage != null)
                {
                    if (backgroundImage.Overlay != null)
                    {
                        backgroundOverlay = backgroundImage.Overlay.Value;
                    }

                    else
                    {
                        //// If there's text on the tile, defaults to 20
                        //if (container.GetAllDescendants().OfType<AdaptiveTextField>().Any())
                        //    backgroundOverlay = 20;

                        //// Else defaults to no overlay
                        //else
                        //    backgroundOverlay = 0;
                    }
                }

                double peekOverlay = 0;

                if (peekImage != null)
                {
                    if (peekImage.Overlay != null)
                    {
                        peekOverlay = peekImage.Overlay.Value;
                    }
                }


                if (backgroundImage != null)
                {
                    switch (backgroundImage.Style)
                    {
                    case JsonTileBackgroundImageStyle.Person:
                        BackgroundImageContainer.Child = new CircleImage()
                        {
                            Source         = ImageHelper.GetBitmap(backgroundImage.Url),
                            Margin         = tileSize == TileSize.Small ? new Thickness(4) : new Thickness(8),
                            OverlayOpacity = backgroundOverlay / 100.0
                        };
                        break;

                    default:
                        BackgroundImageContainer.Child = new Image()
                        {
                            Source  = ImageHelper.GetBitmap(backgroundImage.Url),
                            Stretch = Stretch.UniformToFill
                        };
                        BackgroundImageOverlay.Opacity    = backgroundOverlay / 100.0;
                        BackgroundImageOverlay.Visibility = Visibility.Visible;
                        break;
                    }
                }

                if (peekImage != null)
                {
                    UsingPeek = true;

                    switch (peekImage.Style)
                    {
                    case JsonTileBackgroundImageStyle.Person:
                        PeekImageContainer.Child = new CircleImage()
                        {
                            Source         = ImageHelper.GetBitmap(peekImage.Url),
                            Margin         = tileSize == TileSize.Small ? new Thickness(4) : new Thickness(8),
                            OverlayOpacity = peekOverlay / 100.0
                        };
                        break;

                    default:
                        PeekImageContainer.Child = new Grid()
                        {
                            Children =
                            {
                                new Image()
                                {
                                    Source  = ImageHelper.GetBitmap(peekImage.Url),
                                    Stretch = Stretch.UniformToFill
                                },

                                // Overlay
                                new Rectangle()
                                {
                                    Fill    = new SolidColorBrush(Colors.Black),
                                    Opacity = peekOverlay / 100.0
                                }
                            }
                        };
                        break;
                    }

                    PeekRow.Height = new GridLength(1, GridUnitType.Star);
                }
            }
        }
        /// <summary>
        /// This should only be called once. For new tile notification content, create a new instance of this element.
        /// </summary>
        /// <param name="tileSize"></param>
        /// <param name="tilePixelSize"></param>
        /// <param name="visualElements"></param>
        /// <param name="isBrandingVisible"></param>
        /// <param name="content"></param>
        /// <param name=""></param>
        /// <param name="binding"></param>
        public void Initialize(TileSize tileSize, PreviewTileVisualElements visualElements, bool isBrandingVisible, JsonTileCardContent content, JsonParseTileResult result)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }


            PreviewTileNotificationRaw raw = new PreviewTileNotificationRaw();

            raw.Initialize(tileSize, visualElements, isBrandingVisible, content, result);

            if (raw.UsingPeek)
            {
                base.Content = new PeekDisplayerControl()
                {
                    PreviewTileNotificationRaw = raw,
                    PeekStartsOn = PeekContentDisplayed.Content
                }
            }
            ;

            else
            {
                base.Content = raw;
            }
        }