コード例 #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 InitializeFromXml(TileSize tileSize, PreviewTileVisualElements visualElements, bool isBrandingVisible, AdaptiveBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }


            PreviewTileNotificationRaw raw = new PreviewTileNotificationRaw();

            raw.InitializeFromXml(tileSize, visualElements, isBrandingVisible, binding);

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

            else
            {
                base.Content = raw;
            }
        }
コード例 #2
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="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;
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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 InitializeFromXml(TileSize tileSize, PreviewTileVisualElements visualElements, bool isBrandingVisible, AdaptiveBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            _binding  = binding;
            _tileSize = tileSize;

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

            UsingPeek = false;


            if (binding.Container != null)
            {
                var container = binding.Container;

                // 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
                TileContent.Child = AdaptiveRenderer.Render(container, margin);


                // Background image
                var allImages       = container.GetAllDescendants().OfType <AdaptiveImage>();
                var backgroundImage = allImages.FirstOrDefault(i => i.Placement == Placement.Background);
                var peekImage       = allImages.FirstOrDefault(i => i.Placement == Placement.Peek);

                // 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.HintOverlay != null)
                    {
                        backgroundOverlay = backgroundImage.HintOverlay.Value;
                    }
                    else if (binding.HintOverlay != null)
                    {
                        backgroundOverlay = binding.HintOverlay.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;
                        }
                    }

                    // If we're ignoring the dev specified background when there's no text on the tile
                    if (!binding.SupportedFeatures.RespectDevSpecifiedBackgroundOverlayEvenWhenNoTextOnTile)
                    {
                        if (!container.GetAllDescendants().OfType <AdaptiveTextField>().Any())
                        {
                            backgroundOverlay = 0;
                        }
                    }
                }

                double peekOverlay = 0;

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

                    // New in TH2: Binding overlay applies to both peek and background
                    else if (binding.HintOverlay != null && binding.SupportedFeatures.OverlayForBothBackgroundAndPeek)
                    {
                        peekOverlay = binding.HintOverlay.Value;
                    }

                    // Defaults to 0
                    else
                    {
                        peekOverlay = 0;
                    }
                }


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

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

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

                    switch (peekImage.HintCrop)
                    {
                    case HintCrop.Circle:
                        PeekImageContainer.Child = new CircleImage()
                        {
                            Source         = ImageHelper.GetBitmap(peekImage.Src),
                            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.Src),
                                    Stretch = Stretch.UniformToFill
                                },

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

                    PeekRow.Height = new GridLength(1, GridUnitType.Star);
                }
            }
        }