模块化

This commit is contained in:
hsc
2025-12-23 15:07:51 +08:00
parent 4da28d08a8
commit 72f3b855d8
51 changed files with 1356 additions and 302 deletions

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace UIShare.Converters
{
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool input = value is bool b && b;
bool invert = parameter?.ToString()?.ToLower() == "invert";
if (invert)
input = !input;
return input ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
bool output = value is Visibility v && v == Visibility.Visible;
bool invert = parameter?.ToString()?.ToLower() == "invert";
if (invert)
output = !output;
return output;
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace UIShare.Helpers
{
public static class PasswordBoxHelper
{
public static readonly DependencyProperty PasswordProperty =
DependencyProperty.RegisterAttached(
"Password",
typeof(string),
typeof(PasswordBoxHelper),
new FrameworkPropertyMetadata(
string.Empty,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
OnPasswordPropertyChanged));
public static void SetPassword(DependencyObject d, string value)
=> d.SetValue(PasswordProperty, value);
public static string GetPassword(DependencyObject d)
=> (string)d.GetValue(PasswordProperty);
private static void OnPasswordPropertyChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
if (d is PasswordBox pb)
{
pb.PasswordChanged -= PasswordChanged;
if (pb.Password != (string)e.NewValue)
{
pb.Password = (string)e.NewValue;
}
pb.PasswordChanged += PasswordChanged;
}
}
private static void PasswordChanged(object sender, RoutedEventArgs e)
{
if (sender is PasswordBox pb)
{
SetPassword(pb, pb.Password);
}
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIShare.PubEvent
{
public class LoginSuccessEvent:PubSubEvent
{
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIShare.PubEvent
{
public class OverlayEvent : PubSubEvent<bool>
{
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIShare.PubEvent
{
public class WaitingEvent : PubSubEvent<bool>
{
}
}

View File

@@ -0,0 +1,21 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- 引用MaterialDesign和MahApps的资源 -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml" />
<!-- MahApps资源 -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
<!-- Material Design资源 -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Lime.xaml" />
<!--自定义style-->
<ResourceDictionary Source="/UIShare;component/Styles/WindowStyle.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

View File

@@ -0,0 +1,22 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="DialogUserManageStyle"
TargetType="Window">
<Setter Property="WindowStyle"
Value="None" />
<Setter Property="Topmost"
Value="True" />
<Setter Property="ResizeMode"
Value="NoResize" />
<Setter Property="ShowInTaskbar"
Value="False" />
<Setter Property="AllowsTransparency"
Value="true" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="SizeToContent"
Value="WidthAndHeight" />
</Style>
</ResourceDictionary>

20
UIShare/UIShare.csproj Normal file
View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Prism.Unity" Version="9.0.537" />
<PackageReference Include="MaterialDesignColors" Version="5.3.0" />
<PackageReference Include="MaterialDesignThemes" Version="5.3.0" />
<PackageReference Include="MaterialDesignThemes.MahApps" Version="5.3.0" />
<PackageReference Include="Notifications.Wpf.Core" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Behaviors\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,27 @@
using Notifications.Wpf.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIShare.ViewModelBase
{
public abstract class DialogViewModelBase : BindableBase,IDialogAware
{
public DialogCloseListener RequestClose { get; set; }
public IEventAggregator _eventAggregator;
private INotificationManager _notificationManager;
public DialogViewModelBase(IContainerProvider containerProvider)
{
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
_notificationManager = containerProvider.Resolve<INotificationManager>();
}
#region Dialog
public virtual bool CanCloseDialog() => true;
public virtual void OnDialogClosed() { }
public virtual void OnDialogOpened(IDialogParameters parameters) { }
#endregion
}
}

View File

@@ -0,0 +1,36 @@
using Notifications.Wpf.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UIShare.ViewModelBase
{
public abstract class NavigateViewModelBase : BindableBase, INavigationAware
{
public DialogCloseListener RequestClose { get; set; }
public IEventAggregator _eventAggregator;
public IDialogService _dialogService;
public IRegionManager _regionManager;
private INotificationManager _notificationManager;
public NavigateViewModelBase(IContainerProvider containerProvider)
{
_eventAggregator = containerProvider.Resolve<IEventAggregator>();
_dialogService = containerProvider.Resolve<IDialogService>();
_regionManager = containerProvider.Resolve<IRegionManager>();
_notificationManager = containerProvider.Resolve<INotificationManager>();
}
#region Navigation
public virtual void OnNavigatedTo(NavigationContext navigationContext) { }
public virtual bool IsNavigationTarget(NavigationContext navigationContext) => true;
public virtual void OnNavigatedFrom(NavigationContext navigationContext) { }
#endregion
}
}