直接甩代码!
<Style TargetType="{x:Type local:ShapeRefresh}">
<Setter Property="Width" Value="16"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ShapeRefresh}">
<Grid>
<Viewbox>
<Grid Height="16" Width="16">
<Grid >
<Path Data="M 3,12 A 6,6 0 0 1 8,3" Fill="Transparent" Stroke="{TemplateBinding Foreground}" StrokeThickness="1"/>
<Path Data="M 8,0 L 11,3 L 8,6 Z" Fill="{TemplateBinding Foreground}"/>
</Grid>
<Grid RenderTransformOrigin="0.5,0.5" >
<Grid.RenderTransform>
<RotateTransform Angle="180"/>
</Grid.RenderTransform>
<Path Data="M 3,12 A 6,6 0 0 1 8,3" Fill="Transparent" Stroke="{TemplateBinding Foreground}" StrokeThickness="1"/>
<Path Data="M 8,0 L 11,3 L 8,6 Z" Fill="{TemplateBinding Foreground}"/>
</Grid>
</Grid>
</Viewbox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
public class ShapeRefresh : Control
{
static ShapeRefresh()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ShapeRefresh), new FrameworkPropertyMetadata(typeof(ShapeRefresh)));
}
}
<UserControl x:Class="SoftRGB.CP.App.UC.RefreshPart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SoftRGB.CP.App.UC"
xmlns:RGBCtrl="clr-namespace:SoftRGB.Controls;assembly=SoftRGB.Controls"
Cursor="Hand" >
<UserControl.Triggers>
<EventTrigger RoutedEvent="MouseEnter" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="ShapeRefresh_Main" Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)" To="#ff9c9b9b" />
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="TextBlock_Main" Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)" To="#ff9c9b9b" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="ShapeRefresh_Main" Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)" To="#ffb9b6b6" />
<ColorAnimation Duration="0:0:0.2" Storyboard.TargetName="TextBlock_Main" Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)" To="#ffb9b6b6" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</UserControl.Triggers>
<Grid Background="Transparent">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Viewbox Width="50" Height="50">
<RGBCtrl:ShapeRefresh x:Name="ShapeRefresh_Main" Foreground="#ffb9b6b6"/>
</Viewbox>
<TextBlock x:Name="TextBlock_Main" Text="点击重新加载" Foreground="#ffb9b6b6" Margin="0,10,0,0"/>
</StackPanel>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
namespace SoftRGB.CP.App.UC
{
/// <summary>
/// RefreshPart.xaml 的交互逻辑
/// </summary>
public partial class RefreshPart : UserControl
{
public RefreshPart()
{
InitializeComponent();
}
/// <summary>
/// 加载刷新组件
/// </summary>
/// <param name="container">加载刷新组件的容器</param>
/// <param name="refreshCallback">点击刷新时的回调</param>
public static void LoadRefreshPart(Panel container, Action refreshCallback)
{
RefreshPart part = new RefreshPart();
container.Children.Add(part);
part.MouseLeftButtonUp += (s, e) =>
{
container.Children.Remove(part);
if (refreshCallback != null)
refreshCallback.Invoke();
};
}
}
}
使用:RefreshPart.LoadRefreshPart(Grid_Root, action); 其中Grid_Root为要刷新的容器,action为执行的方法。。。