예제 #1
0
        protected void HandleChild(ParseResult result, XElement child, string baseUri, bool addImageQuery)
        {
            if (child.IsType("binding"))
            {
                AdaptiveBinding binding = new AdaptiveBinding(Context, SupportedFeatures);
                binding.Parse(result, child, baseUri, addImageQuery);

                if (!result.IsOkForRender())
                {
                    throw new IncompleteElementException();
                }

                this.Add(binding);
            }

            else
            {
                result.AddWarning($"Invalid child {child.Name.LocalName} under visual element.", GetErrorPositionInfo(child));
            }
        }
예제 #2
0
 private void Add(AdaptiveBinding element)
 {
     _bindings.Add(element);
     element.Parent = this;
 }
예제 #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 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);
                }
            }
        }