项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,106 @@
#pragma warning disable SA1402 // File may only contain a single class
namespace FluentTest.ViewModels
{
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using ControlzEx.Theming;
public class ColorViewModel : ViewModel
{
private Color standardColor;
private Color highlightColor;
public ColorViewModel()
{
this.StandardColor = Colors.Black;
this.HighlightColor = Colors.Yellow;
CollectionViewSource.GetDefaultView(ThemeManager.Current.Themes).GroupDescriptions.Add(new PropertyGroupDescription(nameof(Theme.BaseColorScheme)));
}
public Color StandardColor
{
get { return this.standardColor; }
set
{
if (value == this.standardColor)
{
return;
}
this.standardColor = value;
this.OnPropertyChanged();
}
}
public Color HighlightColor
{
get { return this.highlightColor; }
set
{
if (value == this.highlightColor)
{
return;
}
this.highlightColor = value;
this.OnPropertyChanged();
}
}
public Color[] ThemeColors { get; } = { Colors.Red, Colors.Green, Colors.Blue, Colors.White, Colors.Black, Colors.Purple };
#pragma warning disable INPC010 // The property sets a different field than it returns.
public Color ThemeColor
{
get => ((SolidColorBrush)Application.Current.Resources["Fluent.Ribbon.Brushes.AccentBaseColorBrush"])?.Color ?? Colors.Pink;
set
{
var solidColorBrush = new SolidColorBrush(value);
solidColorBrush.Freeze();
Application.Current.Resources["Fluent.Ribbon.Brushes.AccentBaseColorBrush"] = solidColorBrush;
this.OnPropertyChanged();
}
}
#pragma warning restore INPC010 // The property sets a different field than it returns.
public string CurrentBaseColor
{
get => this.CurrentTheme.BaseColorScheme;
set
{
if (value is null)
{
return;
}
ThemeManager.Current.ChangeThemeBaseColor(Application.Current, value);
this.OnPropertyChanged();
this.OnPropertyChanged(nameof(this.CurrentTheme));
}
}
public Theme CurrentTheme
{
get => ThemeManager.Current.DetectTheme(Application.Current);
set
{
if (value is null)
{
return;
}
ThemeManager.Current.ChangeTheme(Application.Current, value);
this.OnPropertyChanged();
this.OnPropertyChanged(nameof(this.CurrentBaseColor));
}
}
}
}

View File

@@ -0,0 +1,10 @@
namespace FluentTest.ViewModels
{
using System.Collections.ObjectModel;
using System.Linq;
public class FontsViewModel : ViewModel
{
public ObservableCollection<string> FontsData { get; } = new ObservableCollection<string>(System.Windows.Media.Fonts.SystemFontFamilies.Select(fontFamily => fontFamily.ToString()));
}
}

View File

@@ -0,0 +1,46 @@
namespace FluentTest.ViewModels
{
public class GalleryItemViewModel : ViewModel
{
private string text;
private string group;
public GalleryItemViewModel(string group, string text)
{
this.Group = group;
this.Text = text;
}
public string Text
{
get { return this.text; }
set
{
if (value == this.text)
{
return;
}
this.text = value;
this.OnPropertyChanged();
}
}
public string Group
{
get { return this.group; }
set
{
if (value == this.group)
{
return;
}
this.group = value;
this.OnPropertyChanged();
}
}
}
}

View File

@@ -0,0 +1,59 @@
namespace FluentTest.ViewModels
{
using System.Diagnostics;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Fluent.Converters;
using FluentTest.Commanding;
public class GallerySampleDataItemViewModel : ViewModel
{
/// <summary>
/// Creates new item
/// </summary>
/// <param name="icon">Icon</param>
/// <param name="iconLarge">Large Icon</param>
/// <param name="text">Text</param>
/// <param name="group">Group</param>
/// <returns>Item</returns>
public static GallerySampleDataItemViewModel Create(string icon, string iconLarge, string text, string group)
{
var dataItem = new GallerySampleDataItemViewModel(icon, iconLarge, text, group);
return dataItem;
}
private GallerySampleDataItemViewModel(string icon, string iconLarge, string text, string group)
{
this.Icon = (ImageSource)StaticConverters.ObjectToImageConverter.Convert(icon, typeof(BitmapImage), null, null);
this.IconLarge = (ImageSource)StaticConverters.ObjectToImageConverter.Convert(iconLarge, typeof(BitmapImage), null, null);
this.Text = text;
this.Group = group;
this.Command = new RelayCommand(() => Trace.WriteLine("Command executed"));
}
/// <summary>
/// Gets or sets icon
/// </summary>
public ImageSource Icon { get; }
/// <summary>
/// Gets or sets large icon
/// </summary>
public ImageSource IconLarge { get; }
/// <summary>
/// Gets or sets text
/// </summary>
public string Text { get; }
/// <summary>
/// Gets or sets group name
/// </summary>
public string Group { get; }
public ICommand Command { get; }
}
}

View File

@@ -0,0 +1,70 @@
namespace FluentTest.ViewModels
{
using System.Collections.ObjectModel;
using System.Windows.Input;
using FluentTest.Commanding;
public class GalleryViewModel : ViewModel
{
private ObservableCollection<GalleryItemViewModel> items;
public GalleryViewModel()
{
this.Items = new ObservableCollection<GalleryItemViewModel>();
this.RefreshCommand = new RelayCommand(this.Refresh);
this.Refresh();
}
public ObservableCollection<GalleryItemViewModel> Items
{
get { return this.items; }
private set
{
if (Equals(value, this.items))
{
return;
}
this.items = value;
this.OnPropertyChanged();
}
}
public ICommand RefreshCommand { get; private set; }
public void Refresh()
{
this.Items.Clear();
this.Items.Add(new GalleryItemViewModel("Group 1", "1"));
this.Items.Add(new GalleryItemViewModel("Group 1", "2"));
this.Items.Add(new GalleryItemViewModel("Group 1", "3"));
this.Items.Add(new GalleryItemViewModel("Group 1", "4"));
this.Items.Add(new GalleryItemViewModel("Group 1", "5"));
this.Items.Add(new GalleryItemViewModel("Group 1", "6"));
this.Items.Add(new GalleryItemViewModel("Group 2", "10"));
this.Items.Add(new GalleryItemViewModel("Group 2", "20"));
this.Items.Add(new GalleryItemViewModel("Group 2", "30"));
this.Items.Add(new GalleryItemViewModel("Group 2", "40"));
this.Items.Add(new GalleryItemViewModel("Group 2", "50"));
this.Items.Add(new GalleryItemViewModel("Group 2", "60"));
this.Items.Add(new GalleryItemViewModel("Group 3", "100"));
this.Items.Add(new GalleryItemViewModel("Group 3", "200"));
this.Items.Add(new GalleryItemViewModel("Group 3", "300"));
this.Items.Add(new GalleryItemViewModel("Group 3", "400"));
this.Items.Add(new GalleryItemViewModel("Group 3", "500"));
this.Items.Add(new GalleryItemViewModel("Group 3", "600"));
this.Items.Add(new GalleryItemViewModel("Group 4", "1000"));
this.Items.Add(new GalleryItemViewModel("Group 4", "2000"));
this.Items.Add(new GalleryItemViewModel("Group 4", "3000"));
this.Items.Add(new GalleryItemViewModel("Group 4", "4000"));
this.Items.Add(new GalleryItemViewModel("Group 4", "5000"));
this.Items.Add(new GalleryItemViewModel("Group 4", "6000"));
}
}
}

View File

@@ -0,0 +1,114 @@
namespace FluentTest.ViewModels.IssueRepros
{
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using ControlzEx.Theming;
using Fluent.Extensions;
using FluentTest.Commanding;
public class ThemeManagerFromThread
{
private int currentTheme;
private CancellationTokenSource cancellationTokenSource;
public enum ThemeColors
{
Red,
Amber,
Emerald,
}
public ThemeManagerFromThread()
{
this.StartStopCommand = new RelayCommand(this.StartStop);
}
public RelayCommand StartStopCommand { get; set; }
private void Info(string info)
{
Trace.WriteLine($@"{DateTime.Now} {info}");
}
private void StartStop()
{
if (this.cancellationTokenSource != null)
{
ThemeManager.Current.ThemeChanged -= this.ThemeManagerThemeChangedHandler;
this.cancellationTokenSource.Cancel();
}
else
{
ThemeManager.Current.ThemeChanged += this.ThemeManagerThemeChangedHandler;
Task.Factory.StartNew(async () =>
{
while (this.cancellationTokenSource.IsCancellationRequested == false)
{
this.ThreadProc();
await Task.Delay(TimeSpan.FromSeconds(2));
}
this.cancellationTokenSource.Dispose();
this.cancellationTokenSource = null;
}, (this.cancellationTokenSource = new CancellationTokenSource()).Token);
}
}
private void ThreadProc()
{
if (this.currentTheme > 2)
{
this.currentTheme = 0;
}
var newTheme = (ThemeColors)this.currentTheme;
this.Info("Changing theme to " + newTheme);
this.ChangeTheme(newTheme);
this.currentTheme++;
}
private void ChangeTheme(ThemeColors themeColor)
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.RunInDispatcherAsync(() => this.ChangeTheme(themeColor));
}
else
{
var newTheme = ThemeManager.Current.GetTheme("Light." + themeColor.ToString());
if (newTheme != null)
{
ThemeManager.Current.ChangeTheme(Application.Current, newTheme);
this.Info($"Change theme: NewTheme: {newTheme.Name} Theme changed.");
}
else
{
this.Info($"Change theme: Theme not found: {themeColor}.");
}
}
}
private void ThemeManagerThemeChangedHandler(object sender, ThemeChangedEventArgs e)
{
try
{
var theme = ThemeManager.Current.DetectTheme(Application.Current);
this.Info($"Current theme from args: {e.NewTheme.Name}");
this.Info($"Current theme from detection: {theme.Name}");
}
catch (Exception ex)
{
this.Info(ex.Message);
}
}
}
}

View File

@@ -0,0 +1,14 @@
namespace FluentTest.ViewModels
{
using FluentTest.ViewModels.IssueRepros;
public class IssueReprosViewModel
{
public IssueReprosViewModel()
{
this.ThemeManagerFromThread = new ThemeManagerFromThread();
}
public ThemeManagerFromThread ThemeManagerFromThread { get; }
}
}

View File

@@ -0,0 +1,263 @@
namespace FluentTest.ViewModels
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Timers;
using System.Windows;
using System.Windows.Input;
using Fluent;
using FluentTest.Commanding;
#if MahApps_Metro
#endif
public class MainViewModel : ViewModel
{
private readonly Timer memoryTimer;
private int boundSpinnerValue;
private ColorViewModel colorViewModel;
private FontsViewModel fontsViewModel;
private GalleryViewModel galleryViewModel;
private GallerySampleDataItemViewModel[] dataItems;
private RelayCommand exitCommand;
private double zoom;
private ICommand testCommand;
private IList<string> manyItems;
private IList<string> stringItems;
private bool? isCheckedToggleButton3 = true;
private bool areContextGroupsVisible = true;
public MainViewModel()
{
this.Zoom = 1.0;
this.BoundSpinnerValue = 1;
this.IsCheckedToggleButton3 = true;
this.ColorViewModel = new ColorViewModel();
this.FontsViewModel = new FontsViewModel();
this.GalleryViewModel = new GalleryViewModel();
this.IssueReprosViewModel = new IssueReprosViewModel();
this.PreviewCommand = new RelayCommand<GalleryItem>(Preview);
this.CancelPreviewCommand = new RelayCommand<GalleryItem>(CancelPreview);
this.GroupByAdvancedSample = x => ((GallerySampleDataItemViewModel)x).Text.Substring(0, 1);
this.memoryTimer = new Timer(TimeSpan.FromSeconds(5).TotalMilliseconds);
this.memoryTimer.Elapsed += this.HandleMemoryTimer_Elapsed;
this.memoryTimer.Start();
}
#region Properties
public long UsedMemory => GC.GetTotalMemory(true) / 1014;
public double Zoom
{
get { return this.zoom; }
set
{
if (value.Equals(this.zoom))
{
return;
}
this.zoom = value;
this.OnPropertyChanged();
}
}
public bool AreContextGroupsVisible
{
get => this.areContextGroupsVisible;
set
{
if (value == this.areContextGroupsVisible)
{
return;
}
this.areContextGroupsVisible = value;
this.OnPropertyChanged();
}
}
public ColorViewModel ColorViewModel
{
get { return this.colorViewModel; }
private set
{
if (Equals(value, this.colorViewModel))
{
return;
}
this.colorViewModel = value;
this.OnPropertyChanged();
}
}
public FontsViewModel FontsViewModel
{
get { return this.fontsViewModel; }
private set
{
if (Equals(value, this.fontsViewModel))
{
return;
}
this.fontsViewModel = value;
this.OnPropertyChanged();
}
}
public GalleryViewModel GalleryViewModel
{
get { return this.galleryViewModel; }
private set
{
if (Equals(value, this.galleryViewModel))
{
return;
}
this.galleryViewModel = value;
this.OnPropertyChanged();
}
}
public IssueReprosViewModel IssueReprosViewModel { get; }
/// <summary>
/// Gets data items (uses as DataContext)
/// </summary>
public GallerySampleDataItemViewModel[] DataItems
{
get
{
return this.dataItems ?? (this.dataItems = new[]
{
GallerySampleDataItemViewModel.Create("Images\\Blue.png", "Images\\BlueLarge.png", "Blue", "Group A"),
GallerySampleDataItemViewModel.Create("Images\\Brown.png", "Images\\BrownLarge.png", "Brown", "Group A"),
GallerySampleDataItemViewModel.Create("Images\\Gray.png", "Images\\GrayLarge.png", "Gray", "Group A"),
GallerySampleDataItemViewModel.Create("Images\\Green.png", "Images\\GreenLarge.png", "Green", "Group A"),
GallerySampleDataItemViewModel.Create("Images\\Orange.png", "Images\\OrangeLarge.png", "Orange", "Group A"),
GallerySampleDataItemViewModel.Create("Images\\Pink.png", "Images\\PinkLarge.png", "Pink", "Group B"),
GallerySampleDataItemViewModel.Create("Images\\Red.png", "Images\\RedLarge.png", "Red", "Group B"),
GallerySampleDataItemViewModel.Create("Images\\Yellow.png", "Images\\YellowLarge.png", "Yellow", "Group B"),
});
}
}
public Func<object, string> GroupByAdvancedSample { get; private set; }
public IList<string> ManyItems
{
get { return this.manyItems ?? (this.manyItems = GenerateStrings(5000)); }
}
public IList<string> StringItems
{
get { return this.stringItems ?? (this.stringItems = GenerateStrings(25)); }
}
public bool? IsCheckedToggleButton3
{
get { return this.isCheckedToggleButton3; }
set
{
if (value == this.isCheckedToggleButton3)
{
return;
}
this.isCheckedToggleButton3 = value;
this.OnPropertyChanged();
}
}
public ICommand PreviewCommand { get; private set; }
public ICommand CancelPreviewCommand { get; private set; }
public int BoundSpinnerValue
{
get { return this.boundSpinnerValue; }
set
{
if (value == this.boundSpinnerValue)
{
return;
}
this.boundSpinnerValue = value;
this.OnPropertyChanged();
}
}
#region Exit
/// <summary>
/// Exit from the application
/// </summary>
public ICommand ExitCommand
{
get
{
if (this.exitCommand is null)
{
this.exitCommand = new RelayCommand(Application.Current.Shutdown, () => this.BoundSpinnerValue > 0);
}
return this.exitCommand;
}
}
#endregion
public ICommand TestCommand
{
get { return this.testCommand ?? (this.testCommand = new RelayCommand(() => MessageBox.Show("Test-Command"))); }
}
#endregion Properties
private static void Preview(GalleryItem galleryItem)
{
Trace.WriteLine($"Preview: {galleryItem}");
}
private static void CancelPreview(GalleryItem galleryItem)
{
Trace.WriteLine($"CancelPreview: {galleryItem}");
}
private static IList<string> GenerateStrings(int count)
{
return Enumerable.Range(0, count)
.Select(x => "Item " + (x + 1).ToString())
.ToList();
}
private void HandleMemoryTimer_Elapsed(object sender, ElapsedEventArgs e)
{
this.OnPropertyChanged(nameof(this.UsedMemory));
}
}
}

View File

@@ -0,0 +1,17 @@
namespace FluentTest.ViewModels
{
using System.ComponentModel;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
public class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}