-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 支持隐藏侧边栏 * 更新迁移根目录配置
- Loading branch information
Showing
20 changed files
with
428 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Desktop/RodelAgent.UI/Controls/Base/VisibilityToggleButton.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<UserControl | ||
x:Class="RodelAgent.UI.Controls.VisibilityToggleButton" | ||
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:ic="using:FluentIcons.WinUI" | ||
xmlns:local="using:RodelAgent.UI.Controls" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
mc:Ignorable="d"> | ||
|
||
<Grid | ||
Width="20" | ||
VerticalAlignment="Stretch" | ||
Background="{ThemeResource SubtleFillColorTransparent}"> | ||
<Grid | ||
x:Name="BackGrid" | ||
Width="20" | ||
Height="30" | ||
VerticalAlignment="Center" | ||
Background="{ThemeResource SolidBackgroundFillColorBaseBrush}" | ||
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}" | ||
BorderThickness="1" | ||
CornerRadius="{x:Bind CornerRadius, Mode=OneWay}" | ||
Visibility="Collapsed" /> | ||
<Button | ||
x:Name="Btn" | ||
Width="20" | ||
Height="30" | ||
Padding="0" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
HorizontalContentAlignment="Center" | ||
VerticalContentAlignment="Center" | ||
BorderThickness="0" | ||
Click="OnBtnClick" | ||
CornerRadius="{x:Bind CornerRadius, Mode=OneWay}" | ||
Visibility="Collapsed"> | ||
<ic:SymbolIcon | ||
x:Name="Icon" | ||
FontSize="10" | ||
Symbol="ChevronRight" /> | ||
</Button> | ||
</Grid> | ||
</UserControl> |
132 changes: 132 additions & 0 deletions
132
src/Desktop/RodelAgent.UI/Controls/Base/VisibilityToggleButton.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright (c) Rodel. All rights reserved. | ||
|
||
using Microsoft.UI.Xaml.Automation; | ||
using Microsoft.UI.Xaml.Media; | ||
using RodelAgent.UI.Toolkits; | ||
|
||
namespace RodelAgent.UI.Controls; | ||
|
||
/// <summary> | ||
/// 可见性切换按钮. | ||
/// </summary> | ||
public sealed partial class VisibilityToggleButton : UserControl | ||
{ | ||
/// <summary> | ||
/// <see cref="Direction"/> 依赖属性. | ||
/// </summary> | ||
public static readonly DependencyProperty DirectionProperty = | ||
DependencyProperty.Register(nameof(Direction), typeof(VisibilityToggleButtonDirection), typeof(VisibilityToggleButton), new PropertyMetadata(VisibilityToggleButtonDirection.LeftToRightVisible)); | ||
|
||
/// <summary> | ||
/// <see cref="IsHide"/> 依赖属性. | ||
/// </summary> | ||
public static readonly DependencyProperty IsHideProperty = | ||
DependencyProperty.Register(nameof(IsHide), typeof(bool), typeof(VisibilityToggleButton), new PropertyMetadata(default, new PropertyChangedCallback(OnIsHideChanged))); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="VisibilityToggleButton"/> class. | ||
/// </summary> | ||
public VisibilityToggleButton() | ||
{ | ||
InitializeComponent(); | ||
Loaded += OnLoaded; | ||
} | ||
|
||
/// <summary> | ||
/// 点击事件. | ||
/// </summary> | ||
public event EventHandler Click; | ||
|
||
/// <summary> | ||
/// 获取或设置方向. | ||
/// </summary> | ||
public VisibilityToggleButtonDirection Direction | ||
{ | ||
get => (VisibilityToggleButtonDirection)GetValue(DirectionProperty); | ||
set => SetValue(DirectionProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// 是否已经隐藏指定目标. | ||
/// </summary> | ||
public bool IsHide | ||
{ | ||
get => (bool)GetValue(IsHideProperty); | ||
set => SetValue(IsHideProperty, value); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnPointerEntered(PointerRoutedEventArgs e) | ||
=> ShowButton(); | ||
|
||
/// <inheritdoc/> | ||
protected override void OnPointerMoved(PointerRoutedEventArgs e) | ||
=> ShowButton(); | ||
|
||
/// <inheritdoc/> | ||
protected override void OnPointerExited(PointerRoutedEventArgs e) | ||
=> HideButton(); | ||
|
||
/// <inheritdoc/> | ||
protected override void OnPointerCanceled(PointerRoutedEventArgs e) | ||
=> HideButton(); | ||
|
||
private static void OnIsHideChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
var instance = d as VisibilityToggleButton; | ||
instance?.CheckButtonStates(); | ||
} | ||
|
||
private void OnLoaded(object sender, RoutedEventArgs e) | ||
=> CheckButtonStates(); | ||
|
||
private void CheckButtonStates() | ||
{ | ||
var symbol = IsHide | ||
? Direction == VisibilityToggleButtonDirection.LeftToRightVisible ? FluentIcons.Common.Symbol.ChevronRight : FluentIcons.Common.Symbol.ChevronLeft | ||
: Direction == VisibilityToggleButtonDirection.LeftToRightVisible ? FluentIcons.Common.Symbol.ChevronLeft : FluentIcons.Common.Symbol.ChevronRight; | ||
Icon.Symbol = symbol; | ||
var tip = IsHide ? ResourceToolkit.GetLocalizedString(Models.Constants.StringNames.Show) : ResourceToolkit.GetLocalizedString(Models.Constants.StringNames.Hide); | ||
ToolTipService.SetToolTip(Btn, tip); | ||
AutomationProperties.SetName(Btn, tip); | ||
|
||
var container = VisualTreeHelper.GetParent(this) as FrameworkElement; | ||
if (container is not null) | ||
{ | ||
container.Margin = IsHide | ||
? Direction == VisibilityToggleButtonDirection.LeftToRightVisible ? new Thickness(-4, 0, 0, 0) : new Thickness(0, 0, -4, 0) | ||
: new Thickness(0); | ||
} | ||
} | ||
|
||
private void OnBtnClick(object sender, RoutedEventArgs e) | ||
=> Click?.Invoke(this, EventArgs.Empty); | ||
|
||
private void ShowButton() | ||
{ | ||
BackGrid.Visibility = Visibility.Visible; | ||
Btn.Visibility = Visibility.Visible; | ||
} | ||
|
||
private void HideButton() | ||
{ | ||
BackGrid.Visibility = Visibility.Collapsed; | ||
Btn.Visibility = Visibility.Collapsed; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 可见性切换按钮方向. | ||
/// </summary> | ||
public enum VisibilityToggleButtonDirection | ||
{ | ||
/// <summary> | ||
/// 需要控制的内容在左侧. | ||
/// </summary> | ||
LeftToRightVisible, | ||
|
||
/// <summary> | ||
/// 需要控制的内容在右侧. | ||
/// </summary> | ||
RightToLeftVisible, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.