private void InitializeContent(ICortana cortanaContent)
        {
            BorderContentContainer.Child = null;
            HasContent = false;

            if (cortanaContent == null || cortanaContent.Visual == null)
            {
                return;
            }

            var binding = cortanaContent.Visual.Bindings.FirstOrDefault(i => i.Template == Model.Enums.Template.CortanaGeneric);

            if (binding == null)
            {
                return;
            }

            HasContent = true;

            PreviewTileNotification notif = new PreviewTileNotification()
            {
                RequestedTheme = ElementTheme.Light
            };

            notif.InitializeFromXml(TileSize.Large, new PreviewTileVisualElements()
            {
                BackgroundColor = Colors.Transparent
            }, isBrandingVisible: false,
                                    binding: binding);

            BorderContentContainer.Child = notif;
        }
Esempio n. 2
0
        internal void Show(object tile, bool animate, JsonParseTileResult result = null)
        {
            // Ensure valid object passed in
            if (tile != null && !(tile is ITile) && !(tile is JsonTileContent))
            {
                throw new InvalidOperationException("tile must be of type ITile or JsonTileContent");
            }

            // If animations are disabled, set animate to false
            if (!IsAnimationEnabled)
            {
                animate = false;
            }

            // Store the current tile data, so that when the size changes, we can re-render using the data
            _notificationData = tile;

            // If we're already animating, we'll wait till current animation is done, and then render/animate the new content
            if (animate && _isAnimating)
            {
                _isWaitingToShow = true;
                return;
            }

            // Otherwise we'll render/animate now
            _isWaitingToShow = false;

            // Reset things that a previous notification might have changed, like DisplayName
            ResetDisplayProperties();


            // If nothing to display, revert to default
            if (tile == null)
            {
                ShowDefault(animate);
                return;
            }

            // Find the first matching template for the current size, or if none, revert to default
            if (tile is ITile)
            {
                var xmlTile = tile as ITile;

                var binding = xmlTile.Visual.Bindings.FirstOrDefault(m => GetValidTemplateValues().Contains(m.Template));
                if (binding == null)
                {
                    ShowDefault(animate);
                    return;
                }

                _hasNotificationForCurrentSize = true;


                // Custom display name from visual level
                if (xmlTile.Visual.DisplayName != null)
                {
                    _customDisplayName = xmlTile.Visual.DisplayName;
                    UpdateDisplayName();
                }

                // Custom display name from binding level (which overrides visual)
                if (binding.DisplayName != null)
                {
                    _customDisplayName = binding.DisplayName;
                    UpdateDisplayName();
                }



                // Update branding from notification
                _notificationBranding = xmlTile.Visual.Branding; // first attempt to use branding specified in the visual

                if (binding.Branding != null)
                {
                    _notificationBranding = binding.Branding; // and then branding has a chance to override it
                }
                UpdateBranding();


                // Generate the actual notification content
                PreviewTileNotification notificationContent = new PreviewTileNotification()
                {
                    RequestedTheme = ElementTheme.Dark
                };
                notificationContent.InitializeFromXml(
                    tileSize: TileSize,
                    //tilePixelSize: TilePixelSize,
                    binding: binding,
                    visualElements: VisualElements,
                    isBrandingVisible: Branding.Visibility == Visibility.Visible);

                // And then show it
                ShowElement(notificationContent, animate);
            }

#if CARDS
            else if (tile is JsonTileContent)
            {
                var jsonTile = tile as JsonTileContent;

                var binding = GetContentForCurrentSize(jsonTile);
                if (binding == null)
                {
                    ShowDefault(animate);
                    return;
                }

                _hasNotificationForCurrentSize = true;


                // Custom display name from binding level (which overrides visual)
                if (binding.DisplayName != null)
                {
                    _customDisplayName = binding.DisplayName.Text;
                    UpdateDisplayName();
                }

                // Custom display name from visual level
                else if (jsonTile.Visual.DisplayName != null)
                {
                    _customDisplayName = jsonTile.Visual.DisplayName.Text;
                    UpdateDisplayName();
                }



                // Update branding from notification
                _notificationBranding = ConvertJsonBrandingToXmlBranding(jsonTile.Visual.Branding); // first attempt to use branding specified in the visual

                if (binding.Branding != null)
                {
                    _notificationBranding = ConvertJsonBrandingToXmlBranding(binding.Branding.Value); // and then branding has a chance to override it
                }
                UpdateBranding();


                // Generate the actual notification content
                PreviewTileNotification notificationContent = new PreviewTileNotification()
                {
                    RequestedTheme = ElementTheme.Dark
                };
                notificationContent.Initialize(
                    tileSize: TileSize,
                    //tilePixelSize: TilePixelSize,
                    content: binding,
                    visualElements: VisualElements,
                    isBrandingVisible: Branding.Visibility == Visibility.Visible,
                    result: result);

                // And then show it
                ShowElement(notificationContent, animate);
            }
#endif
        }