拆分按钮样式

This commit is contained in:
wule committed 2026-06-15 20:48:52 +08:00
1 parent d03a1e1466
commit 167885814e
37 files changed
+1009 -219

No files matched your search

@@ -0,0 +1,8 @@
<Button x:Class="_29WxOrderWpf.UserControls.UcImageButton"
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:_29WxOrderWpf.UserControls"
mc:Ignorable="d" Width="30" Height="22">
</Button>
@@ -0,0 +1,55 @@
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.Navigation;
using System.Windows.Shapes;
namespace _29WxOrderWpf.UserControls
{
/// <summary>
/// UcImageButton.xaml 的交互逻辑
/// </summary>
public partial class UcImageButton : Button
{
public UcImageButton()
{
InitializeComponent();
this.DataContext = this;
}
public static readonly DependencyProperty ButtonImageProperty = DependencyProperty.Register(
"ButtonImage", typeof(ImageSource), typeof(UcImageButton), null);
public ImageSource ButtonImage
{
get { return (ImageSource)GetValue(ButtonImageProperty); }
set { SetValue(ButtonImageProperty, value); }
}
public static readonly DependencyProperty MouseOverButtonImageProperty = DependencyProperty.Register(
"MouseOverButtonImage", typeof(ImageSource), typeof(UcImageButton), null);
public ImageSource MouseOverButtonImage
{
get { return (ImageSource)GetValue(MouseOverButtonImageProperty); }
set { SetValue(MouseOverButtonImageProperty, value); }
}
public static readonly DependencyProperty MousePressButtonImageProperty = DependencyProperty.Register(
"MousePressButtonImage", typeof(ImageSource), typeof(UcImageButton), null);
public ImageSource MousePressButtonImage
{
get { return (ImageSource)GetValue(MousePressButtonImageProperty); }
set { SetValue(MousePressButtonImageProperty, value); }
}
}
}
@@ -0,0 +1,66 @@
<UserControl x:Class="_29WxOrderWpf.UserControls.WindowBoxes"
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:_29WxOrderWpf.UserControls"
mc:Ignorable="d" Width="Auto" Height="Auto"
d:DesignHeight="50" d:DesignWidth="300" Background="Black" Loaded="WindowBoxes_Loaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--<local:UcImageButton x:Name="btnMin" Grid.Column="0" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4"
ButtonImage="/Resources/WindowBoxes/min.png"
MouseOverButtonImage="/Resources/WindowBoxes/min.hover.png"
MousePressButtonImage="/Resources/WindowBoxes/min.hover.png" />
<local:UcImageButton x:Name="btnMax" Grid.Column="1" Width="17" Height="17" Background="Transparent" BorderThickness="0" Visibility="Collapsed" Margin="4"
ButtonImage="/Resources/WindowBoxes/max.png"
MouseOverButtonImage="/Resources/WindowBoxes/max.hover.png"
MousePressButtonImage="/Resources/WindowBoxes/max.hover.png" />
<local:UcImageButton x:Name="btnNormal" Grid.Column="2" Width="17" Height="17" Background="Transparent" BorderThickness="0" Visibility="Collapsed" Margin="4"
ButtonImage="/Resources/WindowBoxes/normal.png"
MouseOverButtonImage="/Resources/WindowBoxes/normal.hover.png"
MousePressButtonImage="/Resources/WindowBoxes/normal.hover.png" />
<local:UcImageButton x:Name="btnClose" Grid.Column="3" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4"
ButtonImage="/Resources/WindowBoxes/close.png"
MouseOverButtonImage="/Resources/WindowBoxes/close.hover.png"
MousePressButtonImage="/Resources/WindowBoxes/close.hover.png" />-->
<Button x:Name="btnMin" Grid.Column="0" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4">
<Border>
<Grid>
<Image Source="/Resources/WindowBoxes/min.png" Stretch="Uniform"/>
<Image Source="/Resources/WindowBoxes/min.hover.png" Stretch="Uniform" Visibility="Hidden"/>
</Grid>
</Border>
</Button>
<Button x:Name="btnMax" Grid.Column="1" Width="17" Height="17" Background="Transparent" BorderThickness="0" Visibility="Collapsed" Margin="4">
<Border>
<Grid>
<Image Source="/Resources/WindowBoxes/max.png" Stretch="Uniform"/>
<Image Source="/Resources/WindowBoxes/max.hover.png" Stretch="Uniform" Visibility="Hidden"/>
</Grid>
</Border>
</Button>
<Button x:Name="btnNormal" Grid.Column="2" Width="17" Height="17" Background="Transparent" BorderThickness="0" Visibility="Collapsed" Margin="4">
<Border>
<Grid>
<Image Source="/Resources/WindowBoxes/normal.png" Stretch="Uniform"/>
<Image Source="/Resources/WindowBoxes/normal.hover.png" Stretch="Uniform" Visibility="Hidden"/>
</Grid>
</Border>
</Button>
<Button x:Name="btnClose" Grid.Column="3" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4">
<Border>
<Grid>
<Image Source="/Resources/WindowBoxes/close.png" Stretch="Uniform"/>
<Image Source="/Resources/WindowBoxes/close.hover.png" Stretch="Uniform" Visibility="Hidden"></Image>
</Grid>
</Border>
</Button>
</Grid>
</UserControl>
@@ -0,0 +1,114 @@
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.Navigation;
using System.Windows.Shapes;
namespace _29WxOrderWpf.UserControls
{
/// <summary>
/// WindowBox.xaml 的交互逻辑
/// </summary>
public partial class WindowBoxes : UserControl
{
public static readonly DependencyProperty MaxBoxVisibilityProperty =
DependencyProperty.Register("MaxBoxVisibility", typeof(Visibility), typeof(WindowBoxes),
new PropertyMetadata(default(Visibility)));
public Visibility MaxBoxVisibility
{
get { return (Visibility)GetValue(MaxBoxVisibilityProperty); }
set
{
SetValue(MaxBoxVisibilityProperty, value);
Window_StateChanged(null, null);
}
}
public static readonly DependencyProperty MinBoxVisibilityProperty =
DependencyProperty.Register("MinBoxVisibility", typeof(Visibility), typeof(WindowBoxes),
new PropertyMetadata(default(Visibility)));
public Visibility MinBoxVisibility
{
get { return (Visibility)GetValue(MinBoxVisibilityProperty); }
set { SetValue(MinBoxVisibilityProperty, value); btnMin.Visibility = value; }
}
public WindowBoxes()
{
InitializeComponent();
this.DataContext = this;
}
private void WindowBoxes_Loaded(object sender, RoutedEventArgs e)
{
this.btnClose.Click += BtnClose_Click;
this.btnMax.Click += BtnMax_Click;
this.btnNormal.Click += BtnNormal_Click;
this.btnMin.Click += BtnMin_Click;
var window = Window.GetWindow(this);
if (window != null)
{
window.StateChanged += Window_StateChanged;
}
Window_StateChanged(null, null);
}
private void BtnMin_Click(object sender, RoutedEventArgs e)
{
var window = Window.GetWindow(this);
if (window != null)
window.WindowState = WindowState.Minimized;
}
private void BtnNormal_Click(object sender, RoutedEventArgs e)
{
var window = Window.GetWindow(this);
if (window != null)
window.WindowState = WindowState.Normal;
}
private void BtnMax_Click(object sender, RoutedEventArgs e)
{
var window = Window.GetWindow(this);
if (window != null)
window.WindowState = WindowState.Maximized;
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
var window = Window.GetWindow(this);
if (window == null)
return;
window.Close();
}
private void Window_StateChanged(object sender, EventArgs e)
{
var window = Window.GetWindow(this);
if (window != null)
{
if (window.WindowState == WindowState.Maximized && MaxBoxVisibility == Visibility.Visible)
{
this.btnNormal.Visibility = Visibility.Visible;
this.btnMax.Visibility = Visibility.Collapsed;
}
if (window.WindowState == WindowState.Normal && MaxBoxVisibility == Visibility.Visible)
{
this.btnNormal.Visibility = Visibility.Collapsed;
this.btnMax.Visibility = Visibility.Visible;
}
}
}
}
}