示例#1
0
        internal void PopulateElement(Element_TileBinding binding, TileSize size)
        {
            // Assign properties
            binding.TextStacking = TextStacking;

            // Add the background image if there's one
            if (BackgroundImage != null)
            {
                // And add it as a child
                binding.Children.Add(BackgroundImage.ConvertToElement());
            }

            // Add the peek image if there's one
            if (PeekImage != null)
            {
                var el = PeekImage.ConvertToElement();

                binding.Children.Add(el);
            }

            // And then add all the children
            foreach (var child in Children)
            {
                binding.Children.Add(ConvertToBindingChildElement(child));
            }
        }
示例#2
0
        private static void PopulateElement(ITileBindingContent bindingContent, Element_TileBinding binding, TileSize size)
        {
            if (bindingContent == null)
            {
                return;
            }

            if (bindingContent is TileBindingContentAdaptive)
            {
                (bindingContent as TileBindingContentAdaptive).PopulateElement(binding, size);
            }
            else if (bindingContent is TileBindingContentContact)
            {
                (bindingContent as TileBindingContentContact).PopulateElement(binding, size);
            }
            else if (bindingContent is TileBindingContentIconic)
            {
                (bindingContent as TileBindingContentIconic).PopulateElement(binding, size);
            }
            else if (bindingContent is TileBindingContentPeople)
            {
                (bindingContent as TileBindingContentPeople).PopulateElement(binding, size);
            }
            else if (bindingContent is TileBindingContentPhotos)
            {
                (bindingContent as TileBindingContentPhotos).PopulateElement(binding, size);
            }
            else
            {
                throw new NotImplementedException("Unknown binding content type: " + bindingContent.GetType());
            }
        }
 internal void PopulateElement(Element_TileBinding binding, TileSize size)
 {
     if (Icon != null)
     {
         var element = Icon.ConvertToElement();
         element.Id = 1;
         binding.Children.Add(element);
     }
 }
示例#4
0
        internal void PopulateElement(Element_TileBinding binding, TileSize size)
        {
            binding.Presentation = TilePresentation.Photos;

            foreach (var img in Images)
            {
                binding.Children.Add(img.ConvertToElement());
            }
        }
示例#5
0
        internal Element_TileBinding ConvertToElement(TileSize size)
        {
            TileTemplateNameV3 templateName = GetTemplateName(Content, size);

            Element_TileBinding binding = new Element_TileBinding(templateName)
            {
                Language      = Language,
                BaseUri       = BaseUri,
                Branding      = Branding,
                AddImageQuery = AddImageQuery,
                DisplayName   = DisplayName,
                ContentId     = ContentId,
                Arguments     = Arguments

                                // LockDetailedStatus gets populated by TileVisual
            };

            PopulateElement(Content, binding, size);

            return(binding);
        }
示例#6
0
        internal Element_TileVisual ConvertToElement()
        {
            var visual = new Element_TileVisual()
            {
                Language      = Language,
                BaseUri       = BaseUri,
                Branding      = Branding,
                AddImageQuery = AddImageQuery,
                ContentId     = ContentId,
                DisplayName   = DisplayName,
                Arguments     = Arguments
            };

            if (TileSmall != null)
            {
                visual.Bindings.Add(TileSmall.ConvertToElement(TileSize.Small));
            }

            if (TileMedium != null)
            {
                visual.Bindings.Add(TileMedium.ConvertToElement(TileSize.Medium));
            }

            if (TileWide != null)
            {
                Element_TileBinding wideBindingElement = TileWide.ConvertToElement(TileSize.Wide);

                // If lock detailed status was specified, add them
                if (LockDetailedStatus1 != null)
                {
                    // If we can't reuse existing text element, we'll have to use the hints
                    if (!TryReuseTextElementForLockDetailedText(1, LockDetailedStatus1, wideBindingElement))
                    {
                        wideBindingElement.LockDetailedStatus1 = LockDetailedStatus1;
                    }
                }

                if (LockDetailedStatus2 != null)
                {
                    if (!TryReuseTextElementForLockDetailedText(2, LockDetailedStatus2, wideBindingElement))
                    {
                        wideBindingElement.LockDetailedStatus2 = LockDetailedStatus2;
                    }
                }

                if (LockDetailedStatus3 != null)
                {
                    if (!TryReuseTextElementForLockDetailedText(3, LockDetailedStatus3, wideBindingElement))
                    {
                        wideBindingElement.LockDetailedStatus3 = LockDetailedStatus3;
                    }
                }

                visual.Bindings.Add(wideBindingElement);
            }

            // Otherwise if they specified lock values, throw an exception since lock values require wide
            else if (HasLockDetailedStatusValues())
            {
                throw new Exception("To provide lock detailed status text strings, you must also provide a TileWide binding. Either provide a TileWide binding, or leave the detailed status values null.");
            }

            if (TileLarge != null)
            {
                visual.Bindings.Add(TileLarge.ConvertToElement(TileSize.Large));
            }

            // TODO: If a BaseUri wasn't provided, we can potentially optimize the payload size by calculating the best BaseUri
            return(visual);
        }
示例#7
0
        /// <summary>
        /// Attempts to find and re-use an existing text element inside the binding. Returns true if it could. Otherwise returns false, and the caller will have to specify the detailed status using the lock hint attribute.
        /// </summary>
        /// <param name="lineNumber">The lock screen line number.</param>
        /// <param name="lockText">The lock screen line text.</param>
        /// <param name="binding">The binding to look in for matches.</param>
        /// <returns>True if could re-use existing text element, otherwise false.</returns>
        private static bool TryReuseTextElementForLockDetailedText(int lineNumber, string lockText, Element_TileBinding binding)
        {
            if (lockText == null)
            {
                throw new ArgumentNullException("lockText cannot be null");
            }

            if (binding == null)
            {
                throw new ArgumentNullException("binding cannot be null");
            }

            // If a text element already has an id with the line number (only look at immediate children, since the lockscreen will ignore things under groups/subgroups)
            Element_AdaptiveText matchingIdTextElement = binding.Children.OfType <Element_AdaptiveText>().FirstOrDefault(i => i.Id != null && i.Id.Equals(lineNumber.ToString()));

            if (matchingIdTextElement != null)
            {
                // If the text in the element matches the lock text, then we're good, don't need to assign anything else!
                if (matchingIdTextElement.Text != null && matchingIdTextElement.Text.Equals(lockText))
                {
                    return(true);
                }

                // Otherwise, we need to specify the lock text in the hint attribute, so we return false
                return(false);
            }

            // Otherwise no text elements use that ID, so we could assign one if we find a text element that doesn't have an ID assigned and matches the lock text
            Element_AdaptiveText matchingTextTextElement = binding.Children.OfType <Element_AdaptiveText>().FirstOrDefault(i => i.Id == null && i.Text != null && i.Text.Equals(lockText));

            // If we found text that matched, we'll assign the id so it gets re-used for lock!
            if (matchingTextTextElement != null)
            {
                matchingTextTextElement.Id = lineNumber;
                return(true);
            }

            // Otherwise we'll need to specify lock text in hint attribute, so return false
            return(false);
        }