chore: use file-scoped namespace
This commit is contained in:
1 parent
99d2fafb72
commit
bbf1b7d4c6
748 files changed
+57929
-58678
No files matched your search
@@ -14,178 +14,177 @@ using HandyControlDemo.Service;
|
||||
using HandyControlDemo.Tools;
|
||||
using HandyControlDemo.UserControl;
|
||||
|
||||
namespace HandyControlDemo.ViewModel
|
||||
namespace HandyControlDemo.ViewModel;
|
||||
|
||||
public class MainViewModel : DemoViewModelBase<DemoDataModel>
|
||||
{
|
||||
public class MainViewModel : DemoViewModelBase<DemoDataModel>
|
||||
#region 字段
|
||||
|
||||
/// <summary>
|
||||
/// 内容标题
|
||||
/// </summary>
|
||||
private object _contentTitle;
|
||||
|
||||
/// <summary>
|
||||
/// 子内容
|
||||
/// </summary>
|
||||
private object _subContent;
|
||||
|
||||
private readonly DataService _dataService;
|
||||
|
||||
#endregion
|
||||
|
||||
public MainViewModel(DataService dataService)
|
||||
{
|
||||
#region 字段
|
||||
_dataService = dataService;
|
||||
|
||||
/// <summary>
|
||||
/// 内容标题
|
||||
/// </summary>
|
||||
private object _contentTitle;
|
||||
UpdateMainContent();
|
||||
UpdateLeftContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 子内容
|
||||
/// </summary>
|
||||
private object _subContent;
|
||||
#region 属性
|
||||
|
||||
private readonly DataService _dataService;
|
||||
/// <summary>
|
||||
/// 当前选中的demo项
|
||||
/// </summary>
|
||||
public DemoItemModel DemoItemCurrent { get; private set; }
|
||||
|
||||
#endregion
|
||||
public DemoInfoModel DemoInfoCurrent { get; set; }
|
||||
|
||||
public MainViewModel(DataService dataService)
|
||||
{
|
||||
_dataService = dataService;
|
||||
|
||||
UpdateMainContent();
|
||||
UpdateLeftContent();
|
||||
}
|
||||
|
||||
#region 属性
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中的demo项
|
||||
/// </summary>
|
||||
public DemoItemModel DemoItemCurrent { get; private set; }
|
||||
|
||||
public DemoInfoModel DemoInfoCurrent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子内容
|
||||
/// </summary>
|
||||
public object SubContent
|
||||
{
|
||||
get => _subContent;
|
||||
/// <summary>
|
||||
/// 子内容
|
||||
/// </summary>
|
||||
public object SubContent
|
||||
{
|
||||
get => _subContent;
|
||||
#if NET40
|
||||
set => Set(nameof(SubContent), ref _subContent, value);
|
||||
set => Set(nameof(SubContent), ref _subContent, value);
|
||||
#else
|
||||
set => Set(ref _subContent, value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容标题
|
||||
/// </summary>
|
||||
public object ContentTitle
|
||||
{
|
||||
get => _contentTitle;
|
||||
/// <summary>
|
||||
/// 内容标题
|
||||
/// </summary>
|
||||
public object ContentTitle
|
||||
{
|
||||
get => _contentTitle;
|
||||
#if NET40
|
||||
set => Set(nameof(ContentTitle), ref _contentTitle, value);
|
||||
set => Set(nameof(ContentTitle), ref _contentTitle, value);
|
||||
#else
|
||||
set => Set(ref _contentTitle, value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// demo信息
|
||||
/// </summary>
|
||||
public ObservableCollection<DemoInfoModel> DemoInfoCollection { get; set; }
|
||||
/// <summary>
|
||||
/// demo信息
|
||||
/// </summary>
|
||||
public ObservableCollection<DemoInfoModel> DemoInfoCollection { get; set; }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 命令
|
||||
#region 命令
|
||||
|
||||
/// <summary>
|
||||
/// 切换例子命令
|
||||
/// </summary>
|
||||
public RelayCommand<SelectionChangedEventArgs> SwitchDemoCmd => new(SwitchDemo);
|
||||
/// <summary>
|
||||
/// 切换例子命令
|
||||
/// </summary>
|
||||
public RelayCommand<SelectionChangedEventArgs> SwitchDemoCmd => new(SwitchDemo);
|
||||
|
||||
public RelayCommand OpenPracticalDemoCmd => new(OpenPracticalDemo);
|
||||
public RelayCommand OpenPracticalDemoCmd => new(OpenPracticalDemo);
|
||||
|
||||
public RelayCommand GlobalShortcutInfoCmd => new(() => Growl.Info("Global Shortcut Info"));
|
||||
public RelayCommand GlobalShortcutInfoCmd => new(() => Growl.Info("Global Shortcut Info"));
|
||||
|
||||
public RelayCommand GlobalShortcutWarningCmd => new(() => Growl.Warning("Global Shortcut Warning"));
|
||||
public RelayCommand GlobalShortcutWarningCmd => new(() => Growl.Warning("Global Shortcut Warning"));
|
||||
|
||||
public RelayCommand OpenDocCmd => new(() =>
|
||||
public RelayCommand OpenDocCmd => new(() =>
|
||||
{
|
||||
ControlCommands.OpenLink.Execute(_dataService.GetDemoUrl(DemoInfoCurrent, DemoItemCurrent));
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
#region 方法
|
||||
|
||||
private void UpdateMainContent()
|
||||
{
|
||||
Messenger.Default.Register<object>(this, MessageToken.LoadShowContent, obj =>
|
||||
{
|
||||
ControlCommands.OpenLink.Execute(_dataService.GetDemoUrl(DemoInfoCurrent, DemoItemCurrent));
|
||||
if (SubContent is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
SubContent = obj;
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void UpdateLeftContent()
|
||||
{
|
||||
//clear status
|
||||
Messenger.Default.Register<object>(this, MessageToken.ClearLeftSelected, obj =>
|
||||
{
|
||||
DemoItemCurrent = null;
|
||||
foreach (var item in DemoInfoCollection)
|
||||
{
|
||||
item.SelectedIndex = -1;
|
||||
}
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
#region 方法
|
||||
|
||||
private void UpdateMainContent()
|
||||
Messenger.Default.Register<object>(this, MessageToken.LangUpdated, obj =>
|
||||
{
|
||||
Messenger.Default.Register<object>(this, MessageToken.LoadShowContent, obj =>
|
||||
{
|
||||
if (SubContent is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
SubContent = obj;
|
||||
}, true);
|
||||
}
|
||||
if (DemoItemCurrent == null) return;
|
||||
ContentTitle = LangProvider.GetLang(DemoItemCurrent.Name);
|
||||
});
|
||||
|
||||
private void UpdateLeftContent()
|
||||
{
|
||||
//clear status
|
||||
Messenger.Default.Register<object>(this, MessageToken.ClearLeftSelected, obj =>
|
||||
{
|
||||
DemoItemCurrent = null;
|
||||
foreach (var item in DemoInfoCollection)
|
||||
{
|
||||
item.SelectedIndex = -1;
|
||||
}
|
||||
});
|
||||
|
||||
Messenger.Default.Register<object>(this, MessageToken.LangUpdated, obj =>
|
||||
{
|
||||
if (DemoItemCurrent == null) return;
|
||||
ContentTitle = LangProvider.GetLang(DemoItemCurrent.Name);
|
||||
});
|
||||
|
||||
//load items
|
||||
DemoInfoCollection = new ObservableCollection<DemoInfoModel>();
|
||||
//load items
|
||||
DemoInfoCollection = new ObservableCollection<DemoInfoModel>();
|
||||
#if NET40
|
||||
Task.Factory.StartNew(() =>
|
||||
Task.Factory.StartNew(() =>
|
||||
#else
|
||||
Task.Run(() =>
|
||||
#endif
|
||||
{
|
||||
DataList = _dataService.GetDemoDataList();
|
||||
{
|
||||
DataList = _dataService.GetDemoDataList();
|
||||
|
||||
foreach (var item in _dataService.GetDemoInfo())
|
||||
foreach (var item in _dataService.GetDemoInfo())
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换例子
|
||||
/// </summary>
|
||||
private void SwitchDemo(SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count == 0) return;
|
||||
if (e.AddedItems[0] is DemoItemModel item)
|
||||
{
|
||||
if (Equals(DemoItemCurrent, item)) return;
|
||||
SwitchDemo(item);
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchDemo(DemoItemModel item)
|
||||
{
|
||||
DemoItemCurrent = item;
|
||||
ContentTitle = LangProvider.GetLang(item.Name);
|
||||
var obj = AssemblyHelper.ResolveByKey(item.TargetCtlName);
|
||||
var ctl = obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");
|
||||
Messenger.Default.Send(ctl is IFull, MessageToken.FullSwitch);
|
||||
Messenger.Default.Send(ctl, MessageToken.LoadShowContent);
|
||||
}
|
||||
|
||||
private void OpenPracticalDemo()
|
||||
{
|
||||
Messenger.Default.Send<object>(null, MessageToken.ClearLeftSelected);
|
||||
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
|
||||
Messenger.Default.Send(true, MessageToken.FullSwitch);
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换例子
|
||||
/// </summary>
|
||||
private void SwitchDemo(SelectionChangedEventArgs e)
|
||||
{
|
||||
if (e.AddedItems.Count == 0) return;
|
||||
if (e.AddedItems[0] is DemoItemModel item)
|
||||
{
|
||||
if (Equals(DemoItemCurrent, item)) return;
|
||||
SwitchDemo(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchDemo(DemoItemModel item)
|
||||
{
|
||||
DemoItemCurrent = item;
|
||||
ContentTitle = LangProvider.GetLang(item.Name);
|
||||
var obj = AssemblyHelper.ResolveByKey(item.TargetCtlName);
|
||||
var ctl = obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");
|
||||
Messenger.Default.Send(ctl is IFull, MessageToken.FullSwitch);
|
||||
Messenger.Default.Send(ctl, MessageToken.LoadShowContent);
|
||||
}
|
||||
|
||||
private void OpenPracticalDemo()
|
||||
{
|
||||
Messenger.Default.Send<object>(null, MessageToken.ClearLeftSelected);
|
||||
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
|
||||
Messenger.Default.Send(true, MessageToken.FullSwitch);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user