示例#1
0
        private Viewbox GetBittenCircle(UserAvatarItem avatar)
        {
            if (avatar.Image != null)
            {
                avatar.Image.DecodePixelType   = DecodePixelType.Logical;
                avatar.Image.DecodePixelHeight = (int)Height;
            }

            Viewbox vb = new Viewbox();

            vb.Stretch = Stretch.Uniform;

            Canvas c = new Canvas();

            if (el > 0)
            {
                c.Margin = new Thickness(-8, 0, 0, 0);
            }
            c.Width  = 48;
            c.Height = 48;

            Brush b = new ImageBrush();

            if (avatar.Image != null)
            {
                ImageBrush ib = new ImageBrush();
                ib.ImageSource = avatar.Image;
                ib.Stretch     = Stretch.UniformToFill;
                b = ib;
            }
            else
            {
                b = (SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"];
                Border tb = new Border();
                tb.Height = 48;
                tb.Width  = 48;
                if (!String.IsNullOrEmpty(avatar.Initials))
                {
                    tb.Child = GetTextBlockForCircle(avatar.Initials, true);
                    c.Children.Add(tb);
                }
            }

            string pathxaml = $"<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Fill='#A0A0A0' StrokeThickness='0' Data='M 24 2 A 22 22 0 0 0 2 24 A 22 22 0 0 0 24 46 A 22 22 0 0 0 42.847656 35.296875 A 24.000001 24 0 0 1 40 24 A 24 24 0 0 1 42.84375 12.689453 A 22 22 0 0 0 24 2 z ' />";
            Path   p        = XamlReader.Load(pathxaml) as Path;

            p.Fill = b;

            if (!String.IsNullOrEmpty(avatar.Name))
            {
                ToolTipService.SetToolTip(c, avatar.Name);
            }
            c.Children.Insert(0, p);
            vb.Child = c;
            return(vb);
        }
示例#2
0
        private Viewbox GetCircle(UserAvatarItem avatar = null)
        {
            Viewbox vb = new Viewbox();

            vb.Stretch        = Stretch.Uniform;
            vb.RequestedTheme = ElementTheme.Dark;

            Grid g = new Grid();

            if (el > 0)
            {
                g.Margin = new Thickness(-8, 0, 0, 0);
            }
            g.Width  = 48;
            g.Height = 48;

            Ellipse e = new Ellipse();

            e.Fill = (SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"];
            if (avatar != null)
            {
                if (avatar.Image != null)
                {
                    avatar.Image.DecodePixelType   = DecodePixelType.Logical;
                    avatar.Image.DecodePixelHeight = (int)Height;
                    e.Fill = new ImageBrush()
                    {
                        ImageSource = avatar.Image
                    };
                }
                else if (avatar.Image == null && !String.IsNullOrEmpty(avatar.Initials))
                {
                    g.Children.Add(GetTextBlockForCircle(avatar.Initials, true));
                }
            }
            e.Width  = 44;
            e.Height = 44;
            g.Children.Insert(0, e);
            if (avatar != null && !String.IsNullOrEmpty(avatar.Name))
            {
                ToolTipService.SetToolTip(e, avatar.Name);
            }

            if (avatar == null)
            {
                int z = OverrideAvatarsCount > 0 ? OverrideAvatarsCount : Avatars.Count;
                g.Children.Add(GetTextBlockForCircle($"+{z - MaxDisplayedAvatars}"));
            }

            vb.Child = g;
            return(vb);
        }