模块化
This commit is contained in:
36
UIShare/Converters/BooleanToVisibilityConverter.cs
Normal file
36
UIShare/Converters/BooleanToVisibilityConverter.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
UIShare/Helpers/PasswordBoxHelper.cs
Normal file
52
UIShare/Helpers/PasswordBoxHelper.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
UIShare/PubEvent/LoginSuccessEvent.cs
Normal file
12
UIShare/PubEvent/LoginSuccessEvent.cs
Normal 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
|
||||
{
|
||||
}
|
||||
}
|
||||
12
UIShare/PubEvent/OverlayEvent.cs
Normal file
12
UIShare/PubEvent/OverlayEvent.cs
Normal 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>
|
||||
{
|
||||
}
|
||||
}
|
||||
12
UIShare/PubEvent/WaitingEvent.cs
Normal file
12
UIShare/PubEvent/WaitingEvent.cs
Normal 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>
|
||||
{
|
||||
}
|
||||
}
|
||||
21
UIShare/Styles/CommonStyle.xaml
Normal file
21
UIShare/Styles/CommonStyle.xaml
Normal 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>
|
||||
22
UIShare/Styles/WindowStyle.xaml
Normal file
22
UIShare/Styles/WindowStyle.xaml
Normal 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
20
UIShare/UIShare.csproj
Normal 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>
|
||||
27
UIShare/ViewModelBase/DialogViewModelBase.cs
Normal file
27
UIShare/ViewModelBase/DialogViewModelBase.cs
Normal 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
|
||||
}
|
||||
}
|
||||
36
UIShare/ViewModelBase/NavigateViewModelBase.cs
Normal file
36
UIShare/ViewModelBase/NavigateViewModelBase.cs
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user