support for .NET framework 3.5

Still have bugs
This commit is contained in:
NaBian committed 2019-01-21 00:43:10 +08:00
1 parent 5878039e21
commit 7d6b491f25
704 files changed
+48273 -33

No files matched your search

@@ -0,0 +1,25 @@
using System.Collections.Generic;
using GalaSoft.MvvmLight;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
public class ComboBoxDemoViewModel : ViewModelBase
{
/// <summary>
/// 数据列表
/// </summary>
private List<string> _dataList;
/// <summary>
/// 数据列表
/// </summary>
public List<string> DataList
{
get => _dataList;
set => Set(nameof(DataList), ref _dataList, value);
}
public ComboBoxDemoViewModel(DataService dataService) => DataList = dataService.GetComboBoxDemoDataList();
}
}
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Threading;
using GalaSoft.MvvmLight;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
public class ContributorsViewModel : ViewModelBase
{
/// <summary>
/// 数据列表
/// </summary>
private List<ContributorModel> _dataList;
/// <summary>
/// 数据列表
/// </summary>
public List<ContributorModel> DataList
{
get => _dataList;
set => Set(nameof(DataList), ref _dataList, value);
}
public ContributorsViewModel(DataService dataService)
{
ThreadPool.QueueUserWorkItem(state =>
{
DataList = dataService.GetContributorDataList();
});
}
}
}
@@ -0,0 +1,62 @@
using GalaSoft.MvvmLight.Command;
using HandyControl.Controls;
using HandyControl.Data;
namespace HandyControlDemo.ViewModel
{
public class GrowlDemoViewModel
{
private RelayCommand _infoCmd;
public RelayCommand InfoCmd =>
_infoCmd ?? (_infoCmd = new RelayCommand(() => Growl.Info(Properties.Langs.Lang.GrowlInfo)));
private RelayCommand _successCmd;
public RelayCommand SuccessCmd =>
_successCmd ?? (_successCmd = new RelayCommand(() => Growl.Success(Properties.Langs.Lang.GrowlSuccess)));
private RelayCommand _warningCmd;
public RelayCommand WarningCmd =>
_warningCmd ?? (_warningCmd = new RelayCommand(() =>
Growl.Warning(new GrowlInfo
{
Message = Properties.Langs.Lang.GrowlWarning,
CancelStr = Properties.Langs.Lang.Ignore,
ActionBeforeClose = isConfirmed =>
{
Growl.Info(isConfirmed.ToString());
return true;
}
})));
private RelayCommand _errorCmd;
public RelayCommand ErrorCmd =>
_errorCmd ?? (_errorCmd = new RelayCommand(() => Growl.Error(Properties.Langs.Lang.GrowlError)));
private RelayCommand _askCmd;
public RelayCommand AskCmd =>
_askCmd ?? (_askCmd = new RelayCommand(() =>
Growl.Ask(Properties.Langs.Lang.GrowlAsk, isConfirmed =>
{
Growl.Info(isConfirmed.ToString());
return true;
})));
private RelayCommand _fatalCmd;
public RelayCommand FatalCmd =>
_fatalCmd ?? (_fatalCmd = new RelayCommand(() => Growl.Fatal(new GrowlInfo
{
Message = Properties.Langs.Lang.GrowlFatal,
ShowDateTime = false
})));
private RelayCommand _clearCmd;
public RelayCommand ClearCmd => _clearCmd ?? (_clearCmd = new RelayCommand(Growl.Clear));
}
}
@@ -0,0 +1,15 @@
using System;
using GalaSoft.MvvmLight.Command;
using HandyControl.Controls;
namespace HandyControlDemo.ViewModel
{
public class ImageBrowserDemoViewModel
{
private RelayCommand _openImgCmd;
public RelayCommand OpenImgCmd =>
_openImgCmd ?? (_openImgCmd = new RelayCommand(() =>
new ImageBrowser(new Uri("pack://application:,,,/Resources/Img/1.jpg")).Show()));
}
}
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
using HandyControlDemo.Tools;
namespace HandyControlDemo.ViewModel
{
public class MainViewModel : ViewModelBase
{
#region 字段
/// <summary>
/// 内容标题
/// </summary>
private object _contentTitle;
/// <summary>
/// 子内容
/// </summary>
private object _subContent;
/// <summary>
/// 数据列表
/// </summary>
private List<DemoDataModel> _dataList;
/// <summary>
/// 当前选中的列表项
/// </summary>
private ListBoxItem _listBoxItemCurrent;
#endregion
public MainViewModel(DataService dataService)
{
Messenger.Default.Register<object>(this, MessageToken.LoadShowContent, obj =>
{
if (SubContent is IDisposable disposable)
{
disposable.Dispose();
}
SubContent = obj;
});
Messenger.Default.Register<object>(this, MessageToken.ClearLeftSelected, obj =>
{
if (_listBoxItemCurrent == null) return;
_listBoxItemCurrent.IsSelected = false;
_listBoxItemCurrent = null;
});
DataList = dataService.GetDemoDataList();
}
#region 属性
/// <summary>
/// 数据列表
/// </summary>
public List<DemoDataModel> DataList
{
get => _dataList;
set => Set(nameof(DataList), ref _dataList, value);
}
/// <summary>
/// 子内容
/// </summary>
public object SubContent
{
get => _subContent;
set => Set(nameof(SubContent), ref _subContent, value);
}
/// <summary>
/// 内容标题
/// </summary>
public object ContentTitle
{
get => _contentTitle;
set => Set(nameof(ContentTitle), ref _contentTitle, value);
}
#endregion
#region 命令
private RelayCommand<SelectionChangedEventArgs> _switchDemoCmd;
/// <summary>
/// 切换例子命令
/// </summary>
public RelayCommand<SelectionChangedEventArgs> SwitchDemoCmd =>
_switchDemoCmd ?? (_switchDemoCmd = new RelayCommand<SelectionChangedEventArgs>(SwitchDemo));
#endregion
#region 方法
/// <summary>
/// 切换例子
/// </summary>
private void SwitchDemo(SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 0) return;
if (e.AddedItems[0] is ListBoxItem item)
{
if (item.Tag is string tag)
{
if (Equals(_listBoxItemCurrent, item)) return;
_listBoxItemCurrent = item;
ContentTitle = item.Content;
Messenger.Default.Send(false, MessageToken.FullSwitch);
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{tag}"), MessageToken.LoadShowContent);
}
else
{
_listBoxItemCurrent = null;
ContentTitle = null;
SubContent = null;
}
}
}
#endregion
}
}
@@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Linq;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HandyControl.Data;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
public class PaginationDemoViewModel : ViewModelBase
{
/// <summary>
/// 所有数据
/// </summary>
private readonly List<DemoDataModel> _totalDataList;
/// <summary>
/// 显示的数据
/// </summary>
private List<DemoDataModel> _dataList;
/// <summary>
/// 显示的数据
/// </summary>
public List<DemoDataModel> DataList
{
get => _dataList;
set => Set(nameof(DataList), ref _dataList, value);
}
/// <summary>
/// 页码
/// </summary>
private int _pageIndex = 1;
/// <summary>
/// 页码
/// </summary>
public int PageIndex
{
get => _pageIndex;
set => Set(nameof(PageIndex), ref _pageIndex, value);
}
public PaginationDemoViewModel(DataService dataService)
{
_totalDataList = dataService.GetDemoDataList(100);
DataList = _totalDataList.Take(10).ToList();
}
private RelayCommand<FunctionEventArgs<int>> _pageUpdatedCmd;
/// <summary>
/// 页码改变命令
/// </summary>
public RelayCommand<FunctionEventArgs<int>> PageUpdatedCmd =>
_pageUpdatedCmd ?? (_pageUpdatedCmd = new RelayCommand<FunctionEventArgs<int>>(PageUpdated));
/// <summary>
/// 页码改变
/// </summary>
private void PageUpdated(FunctionEventArgs<int> info)
{
DataList = _totalDataList.Skip((info.Info - 1) * 10).Take(10).ToList();
}
}
}
@@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HandyControl.Controls;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
public class StepBarDemoViewModel : ViewModelBase
{
/// <summary>
/// 数据列表
/// </summary>
private List<StepBarDemoModel> _dataList;
/// <summary>
/// 数据列表
/// </summary>
public List<StepBarDemoModel> DataList
{
get => _dataList;
set => Set(nameof(DataList), ref _dataList, value);
}
public StepBarDemoViewModel(DataService dataService)
{
DataList = dataService.GetStepBarDemoDataList();
}
private RelayCommand<Panel> _nextCmd;
/// <summary>
/// 下一步
/// </summary>
public RelayCommand<Panel> NextCmd => _nextCmd ?? (_nextCmd = new RelayCommand<Panel>(Next));
private RelayCommand<Panel> _prevCmd;
/// <summary>
/// 上一步
/// </summary>
public RelayCommand<Panel> PrevCmd => _prevCmd ?? (_prevCmd = new RelayCommand<Panel>(Prev));
private void Next(Panel panel)
{
foreach (var stepBar in panel.Children.OfType<StepBar>())
{
stepBar.Next();
}
}
private void Prev(Panel panel)
{
foreach (var stepBar in panel.Children.OfType<StepBar>())
{
stepBar.Prev();
}
}
}
}
@@ -0,0 +1,51 @@
using System.Windows;
using GalaSoft.MvvmLight.Ioc;
using HandyControlDemo.Service;
using Microsoft.Practices.ServiceLocation;
namespace HandyControlDemo.ViewModel
{
public class ViewModelLocator
{
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Register<DataService>();
SimpleIoc.Default.Register<MainViewModel>();
SimpleIoc.Default.Register<GrowlDemoViewModel>();
SimpleIoc.Default.Register<ImageBrowserDemoViewModel>();
SimpleIoc.Default.Register<ComboBoxDemoViewModel>();
SimpleIoc.Default.Register<WindowDemoViewModel>();
SimpleIoc.Default.Register<ContributorsViewModel>();
SimpleIoc.Default.Register<StepBarDemoViewModel>();
SimpleIoc.Default.Register<PaginationDemoViewModel>();
}
private static ViewModelLocator _instance;
public static ViewModelLocator Instance =>
_instance ?? (_instance = Application.Current.TryFindResource("Locator") as ViewModelLocator);
#region Vm
public MainViewModel Main => ServiceLocator.Current.GetInstance<MainViewModel>();
public GrowlDemoViewModel GrowlDemo => ServiceLocator.Current.GetInstance<GrowlDemoViewModel>();
public ImageBrowserDemoViewModel ImageBrowserDemo => ServiceLocator.Current.GetInstance<ImageBrowserDemoViewModel>();
public ComboBoxDemoViewModel ComboBoxDemo => ServiceLocator.Current.GetInstance<ComboBoxDemoViewModel>();
public WindowDemoViewModel WindowDemo => ServiceLocator.Current.GetInstance<WindowDemoViewModel>();
public ContributorsViewModel ContributorsView => ServiceLocator.Current.GetInstance<ContributorsViewModel>();
public StepBarDemoViewModel StepBarDemo => ServiceLocator.Current.GetInstance<StepBarDemoViewModel>();
public PaginationDemoViewModel PaginationDemo => ServiceLocator.Current.GetInstance<PaginationDemoViewModel>();
#endregion
}
}
@@ -0,0 +1,23 @@
using System.Windows;
using GalaSoft.MvvmLight.Command;
using HandyControlDemo.Tools;
namespace HandyControlDemo.ViewModel
{
public class WindowDemoViewModel
{
private RelayCommand<string> _openWindowCmd;
public RelayCommand<string> OpenWindowCmd =>
_openWindowCmd ?? (_openWindowCmd = new RelayCommand<string>(OpenWindow));
private void OpenWindow(string windowTag)
{
if (AssemblyHelper.CreateInternalInstance($"Window.{windowTag}") is System.Windows.Window window)
{
window.Owner = Application.Current.MainWindow;
window.ShowDialog();
}
}
}
}