group demo items
This commit is contained in:
1 parent
789eeed609
commit
17d2353107
18 files changed
+256
-162
No files matched your search
@@ -30,64 +30,16 @@ namespace HandyControlDemo.ViewModel
|
||||
/// </summary>
|
||||
private object _subContent;
|
||||
|
||||
private DataService _dataService;
|
||||
private readonly DataService _dataService;
|
||||
|
||||
#endregion
|
||||
|
||||
public MainViewModel(DataService dataService)
|
||||
{
|
||||
_dataService = dataService;
|
||||
Messenger.Default.Register<object>(this, MessageToken.LoadShowContent, obj =>
|
||||
{
|
||||
if (SubContent is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
SubContent = obj;
|
||||
}, true);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
DemoInfoCollection = new ObservableCollection<DemoInfoModel>();
|
||||
|
||||
#if NET40
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
DataList = dataService.GetDemoDataList();
|
||||
foreach (var item in dataService.GetDemoInfo())
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
});
|
||||
#else
|
||||
Task.Run(() =>
|
||||
{
|
||||
DataList = dataService.GetDemoDataList();
|
||||
foreach (var item in dataService.GetDemoInfo())
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
UpdateMainContent();
|
||||
UpdateLeftContent();
|
||||
}
|
||||
|
||||
#region 属性
|
||||
@@ -160,6 +112,56 @@ namespace HandyControlDemo.ViewModel
|
||||
|
||||
#region 方法
|
||||
|
||||
private void UpdateMainContent()
|
||||
{
|
||||
Messenger.Default.Register<object>(this, MessageToken.LoadShowContent, obj =>
|
||||
{
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
Messenger.Default.Register<object>(this, MessageToken.LangUpdated, obj =>
|
||||
{
|
||||
if (DemoItemCurrent == null) return;
|
||||
ContentTitle = LangProvider.GetLang(DemoItemCurrent.Name);
|
||||
});
|
||||
|
||||
//load items
|
||||
DemoInfoCollection = new ObservableCollection<DemoInfoModel>();
|
||||
#if NET40
|
||||
Task.Factory.StartNew(() =>
|
||||
#else
|
||||
Task.Run(() =>
|
||||
#endif
|
||||
{
|
||||
DataList = _dataService.GetDemoDataList();
|
||||
|
||||
foreach (var item in _dataService.GetDemoInfo())
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换例子
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user