Files
Future/Future.Contract/Bubbles/BubbleAdorner.cs
2025-08-30 17:19:57 +08:00

48 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows;
namespace Future.Contract
{
public class BubbleAdorner : Adorner
{
private readonly VisualCollection _visuals;
private readonly Border _bubble;
public BubbleAdorner(UIElement adornedElement) : base(adornedElement)
{
_visuals = new VisualCollection(this);
_bubble = new Border
{
Background = Brushes.LightYellow,
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(2),
Padding = new Thickness(5),
Child = new TextBlock { Text = "气泡提示" }
};
_visuals.Add(_bubble);
}
protected override int VisualChildrenCount => _visuals.Count;
protected override Visual GetVisualChild(int index) => _visuals[index];
protected override Size ArrangeOverride(Size finalSize)
{
var bubbleSize = _bubble.DesiredSize;
bubbleSize = _bubble.RenderSize;
var location = new Point(finalSize.Width + 10, (finalSize.Height - bubbleSize.Height) / 2);
_bubble.Arrange(new Rect(location, DesiredSize));
return finalSize;
}
}
}