Example #1
0
 void CustomizeStackPanel(StackPanel stackPanel, RatingControlStates state)
 {
     foreach (UIElement child in stackPanel.Children)
     {
         CustomizeRatingItem(child, state);
     }
 }
Example #2
0
        ImageSource GetAppropriateImageSource(RatingControlStates type)
        {
            if (!IsItemInfoPresentAndImageInfo())
            {
                Debug.Assert(false, "Runtime error, tried to retrieve an image when the ItemInfo is not a RatingItemImageInfo");
            }

            RatingItemImageInfo imageInfo = (RatingItemImageInfo)ItemInfo;

            switch (type)
            {
            case RatingControlStates.Disabled:
                return(GetNextImageIfNull(imageInfo.DisabledImage, RatingControlStates.Set));

            case RatingControlStates.PointerOverSet:
                return(GetNextImageIfNull(imageInfo.PointerOverImage, RatingControlStates.Set));

            case RatingControlStates.PointerOverPlaceholder:
                return(GetNextImageIfNull(imageInfo.PointerOverPlaceholderImage, RatingControlStates.Placeholder));

            case RatingControlStates.Placeholder:
                return(GetNextImageIfNull(imageInfo.PlaceholderImage, RatingControlStates.Set));

            case RatingControlStates.Unset:
                return(GetNextImageIfNull(imageInfo.UnsetImage, RatingControlStates.Set));

            case RatingControlStates.Null:
                return(null);

            default:
                return(imageInfo.Image);    // "Set" state
            }
        }
Example #3
0
        string GetAppropriateGlyph(RatingControlStates type)
        {
            if (!IsItemInfoPresentAndFontInfo())
            {
                Debug.Fail("Runtime error, tried to retrieve a glyph when the ItemInfo is not a RatingItemGlyphInfo");
            }

            RatingItemFontInfo rifi = (RatingItemFontInfo)ItemInfo;

            switch (type)
            {
            case RatingControlStates.Disabled:
                return(GetNextGlyphIfNull(rifi.DisabledGlyph, RatingControlStates.Set));

            case RatingControlStates.PointerOverSet:
                return(GetNextGlyphIfNull(rifi.PointerOverGlyph, RatingControlStates.Set));

            case RatingControlStates.PointerOverPlaceholder:
                return(GetNextGlyphIfNull(rifi.PointerOverPlaceholderGlyph, RatingControlStates.Placeholder));

            case RatingControlStates.Placeholder:
                return(GetNextGlyphIfNull(rifi.PlaceholderGlyph, RatingControlStates.Set));

            case RatingControlStates.Unset:
                return(GetNextGlyphIfNull(rifi.UnsetGlyph, RatingControlStates.Set));

            case RatingControlStates.Null:
                return(string.Empty);

            default:
                return(rifi.Glyph);    // "Set" state
            }
        }
Example #4
0
        private string GetAppropriateGlyph(RatingControlStates type)
        {
            if (!IsItemInfoPresentAndFontInfo())
            {
                throw new InvalidOperationException("Runtime error, tried to retrieve a glyph when the ItemInfo is not a RatingItemGlyphInfo");
            }

            RatingItemFontInfo rifi = ItemInfo as RatingItemFontInfo;

            switch (type)
            {
            case RatingControlStates.Disabled:
                return(GetNextGlyphIfNull(rifi.DisabledGlyph, RatingControlStates.Set));

            case RatingControlStates.PointerOverSet:
                return(GetNextGlyphIfNull(rifi.PointerOverGlyph, RatingControlStates.Set));

            case RatingControlStates.PointerOverPlaceholder:
                return(GetNextGlyphIfNull(rifi.PointerOverPlaceholderGlyph, RatingControlStates.Placeholder));

            case RatingControlStates.Placeholder:
                return(GetNextGlyphIfNull(rifi.PlaceholderGlyph, RatingControlStates.Set));

            case RatingControlStates.Unset:
                return(GetNextGlyphIfNull(rifi.UnsetGlyph, RatingControlStates.Set));

            case RatingControlStates.Null:
                return(null);

            default:
                return(rifi.Glyph);                        // "Set" state
            }
        }
Example #5
0
 private void CustomizeRatingItem(UIElement ui, RatingControlStates type)
 {
     if (IsItemInfoPresentAndFontInfo())
     {
         var textBlock = ui as TextBlock;
         if (textBlock != null)
         {
             textBlock.FontFamily = FontFamily;
             textBlock.Text       = GetAppropriateGlyph(type);
         }
     }
     else if (IsItemInfoPresentAndImageInfo())
     {
         var image = ui as Image;
         if (image != null)
         {
             image.Source = GetAppropriateImageSource(type);
             image.Width  = RenderingRatingFontSize();                    //
             image.Height = RenderingRatingFontSize();                    // MSFT #10030063 Replacing with Rating size DPs
         }
     }
     else
     {
         throw new InvalidOperationException("ItemInfo property is null");
     }
 }
Example #6
0
        Geometry GetAppropriatePathData(RatingControlStates type)
        {
            if (!IsItemInfoPresentAndPathInfo())
            {
                Debug.Assert(false, "Runtime error, tried to retrieve a geometry when the ItemInfo is not a RatingItemPathInfo");
            }

            RatingItemPathInfo pathInfo = (RatingItemPathInfo)ItemInfo;

            switch (type)
            {
            case RatingControlStates.Disabled:
                return(GetNextGeometryIfNull(pathInfo.DisabledData, RatingControlStates.Set));

            case RatingControlStates.PointerOverSet:
                return(GetNextGeometryIfNull(pathInfo.PointerOverData, RatingControlStates.Set));

            case RatingControlStates.PointerOverPlaceholder:
                return(GetNextGeometryIfNull(pathInfo.PointerOverPlaceholderData, RatingControlStates.Placeholder));

            case RatingControlStates.Placeholder:
                return(GetNextGeometryIfNull(pathInfo.PlaceholderData, RatingControlStates.Set));

            case RatingControlStates.Unset:
                return(GetNextGeometryIfNull(pathInfo.UnsetData, RatingControlStates.Set));

            case RatingControlStates.Null:
                return(null);

            default:
                return(pathInfo.Data);    // "Set" state
            }
        }
Example #7
0
 void CustomizeRatingItem(UIElement ui, RatingControlStates type)
 {
     if (IsItemInfoPresentAndFontInfo())
     {
         if (ui is TextBlock textBlock)
         {
             textBlock.FontFamily = FontFamily;
             textBlock.Text       = GetAppropriateGlyph(type);
         }
     }
     else if (IsItemInfoPresentAndImageInfo())
     {
         if (ui is Image image)
         {
             image.Source = GetAppropriateImageSource(type);
             image.Width  = RenderingRatingFontSize; //
             image.Height = RenderingRatingFontSize; // MSFT #10030063 Replacing with Rating size DPs
         }
     }
     else if (IsItemInfoPresentAndPathInfo())
     {
         if (ui is FontIconFallback pathControl)
         {
             pathControl.Data = GetAppropriatePathData(type);
         }
     }
     else
     {
         Debug.Fail("Runtime error, ItemInfo property is null");
     }
 }
Example #8
0
 ImageSource GetNextImageIfNull(ImageSource image, RatingControlStates fallbackType)
 {
     if (image == null)
     {
         if (fallbackType == RatingControlStates.Null)
         {
             return(null);
         }
         return(GetAppropriateImageSource(fallbackType));
     }
     return(image);
 }
Example #9
0
 string GetNextGlyphIfNull(string glyph, RatingControlStates fallbackType)
 {
     if (string.IsNullOrEmpty(glyph))
     {
         if (fallbackType == RatingControlStates.Null)
         {
             return(string.Empty);
         }
         return(GetAppropriateGlyph(fallbackType));
     }
     return(glyph);
 }
Example #10
0
 Geometry GetNextGeometryIfNull(Geometry geometry, RatingControlStates fallbackType)
 {
     if (geometry == null)
     {
         if (fallbackType == RatingControlStates.Null)
         {
             return(null);
         }
         return(GetAppropriatePathData(fallbackType));
     }
     return(geometry);
 }
Example #11
0
        void PopulateStackPanelWithItems(string templateName, StackPanel stackPanel, RatingControlStates state)
        {
            object lookup = Application.Current.FindResource(templateName);
            var    dt     = (DataTemplate)lookup;

            for (int i = 0; i < MaxRating; i++)
            {
                if (dt.LoadContent() is UIElement ui)
                {
                    CustomizeRatingItem(ui, state);
                    stackPanel.Children.Add(ui);
                    ApplyScaleExpressionAnimation(ui, i);
                }
            }
        }
Example #12
0
        private void PopulateStackPanelWithItems(string templateName, StackPanel stackPanel, RatingControlStates state)
        {
            object lookup = Application.Current.Resources.Lookup(templateName);
            var    dt     = lookup as DataTemplate;

            for (int i = 0; i < MaxRating; i++)
            {
                var ui = dt.LoadContent() as UIElement;
                if (ui != null)
                {
                    CustomizeRatingItem(ui, state);
                    stackPanel.Children.Add(ui);
                    ApplyScaleExpressionAnimation(ui, i);
                }
            }
        }