将以往的代码复制到代码库

This commit is contained in:
于智纯
2025-08-30 17:19:57 +08:00
parent da46e0242d
commit 20ea70bf64
198 changed files with 10075 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
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;
}
}
}

View File

@@ -0,0 +1,25 @@
<Window x:Class="Future.Contract.BubbleWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Future.Contract"
mc:Ignorable="d"
Name="own" AllowsTransparency="True" ShowInTaskbar="False" Background="{x:Null}" Topmost="True" WindowState="Maximized"
Title="BubbleWindow" d:Height="450" d:Width="800" WindowStyle="None" Focusable="False" WindowStartupLocation="CenterScreen">
<Grid>
<Popup Name="XPopup" Opened="XPopup_Opened" Closed="UITimerTick"
StaysOpen="False" IsOpen="False" AllowsTransparency="True"
VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalOffset="100" HorizontalOffset="100"
Placement="Top" PlacementTarget="{Binding Placement,ElementName=own}">
</Popup>
<Border CornerRadius="4" Background="{Binding BackBrush,ElementName=own}" VerticalAlignment="Center" HorizontalAlignment="Center">
<DockPanel LastChildFill="True">
<Viewbox MaxWidth="32" MaxHeight="32" DockPanel.Dock="Left" Stretch="Uniform"/>
<ContentControl Margin="12" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="16" MaxWidth="800"
Content="{Binding InfoContent,ElementName=own}" Foreground="{Binding InfoBrush,ElementName=own}"/>
</DockPanel>
</Border>
</Grid>
</Window>

View File

@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Future.Contract
{
/// <summary>
/// BubbleWindow.xaml 的交互逻辑
/// </summary>
public partial class BubbleWindow : Window
{
public BubbleWindow()
{
InitializeComponent();
this.Loaded += (s, e) => this.XPopup.IsOpen = true;
}
/// <summary>
/// “失去焦点关闭”功能使用的辅助Popup定位位置
/// </summary>
public UIElement Placement
{
get { return (UIElement)GetValue(PlacementProperty); }
set { SetValue(PlacementProperty, value); }
}
// Using a DependencyProperty as the backing store for Element. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PlacementProperty =
DependencyProperty.Register("Placement", typeof(UIElement), typeof(Window), new PropertyMetadata(null));
/// <summary>
/// 信息内容
/// </summary>
public object InfoContent
{
get { return (string)GetValue(InfoContentProperty); }
set { SetValue(InfoContentProperty, value); }
}
// Using a DependencyProperty as the backing store for InfoContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty InfoContentProperty =
DependencyProperty.Register("InfoContent", typeof(object), typeof(Window), new PropertyMetadata(""));
/// <summary>
/// 关闭延时
/// </summary>
public int Delay
{
get { return (int)GetValue(DelayProperty); }
set { SetValue(DelayProperty, value); }
}
// Using a DependencyProperty as the backing store for Delay. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DelayProperty =
DependencyProperty.Register("Delay", typeof(int), typeof(Window), new PropertyMetadata(3));
/// <summary>
/// 背景颜色
/// </summary>
public Brush BackBrush
{
get { return (Brush)GetValue(BackBrushProperty); }
set { SetValue(BackBrushProperty, value); }
}
// Using a DependencyProperty as the backing store for BackBrush. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BackBrushProperty =
DependencyProperty.Register("BackBrush", typeof(Brush), typeof(Window), new PropertyMetadata(new SolidColorBrush(Colors.Gray)));
/// <summary>
/// 前景颜色
/// </summary>
public Brush InfoBrush
{
get { return (Brush)GetValue(InfoBrushProperty); }
set { SetValue(InfoBrushProperty, value); }
}
// Using a DependencyProperty as the backing store for BackBrush. This enables animation, styling, binding, etc...
public static readonly DependencyProperty InfoBrushProperty =
DependencyProperty.Register("InfoBrush", typeof(Brush), typeof(Window), new PropertyMetadata(new SolidColorBrush(Colors.White)));
DateTime mStartTime = DateTime.Now;
System.Windows.Threading.DispatcherTimer mUiTimer = new System.Windows.Threading.DispatcherTimer();
/// <summary>
/// 计时器到时检查是否需要关闭提示
/// </summary>
private void UITimerTick(object sender, EventArgs e)
{
if (XPopup.IsOpen == false)
{
if (this.Delay > 0) mUiTimer.Stop();
this.Close();
}
if ((DateTime.Now - mStartTime).TotalSeconds >= Delay)
{
XPopup.IsOpen = false;
this.Close();
}
}
/// <summary>
/// Popup打开时开启计时器
/// </summary>
private void XPopup_Opened(object sender, EventArgs e)
{
if (this.Delay <= 0) return;
if (mUiTimer.IsEnabled == false)
{
mUiTimer = new System.Windows.Threading.DispatcherTimer();
mUiTimer.Interval = TimeSpan.FromMilliseconds(500);
mUiTimer.Tick += UITimerTick;
mStartTime = DateTime.Now;
mUiTimer.Start();
}
else mStartTime = DateTime.Now;
}
/// <summary>
/// 显示一个气泡提示
/// </summary>
/// <param name="infoContent">提示信息:可以是文本,也可以是所有可视化元素</param>
/// <param name="placement">焦点丢失关闭功能的辅助器定位位置</param>
/// <param name="delayTime">自动关闭延时</param>
/// <param name="autoClose">是否自动关闭</param>
public static void ShowBubble(object infoContent, FrameworkElement placement = null, int delayTime = 1, bool autoClose = true)
{
BubbleWindow window = new BubbleWindow();
window.Placement = placement;
window.InfoContent = infoContent;
window.Delay = delayTime;
window.Show();
}
}
}