optimized demo start-up speed
This commit is contained in:
1 parent
39b1296727
commit
b57e6e8961
5 files changed
+94
-38
No files matched your search
@@ -25,7 +25,6 @@ namespace HandyControlDemo.Tools
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var type = Type.GetType($"{NameSpaceStr}.{className}");
|
||||
return type == null ? null : Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</Border.Resources>
|
||||
<DockPanel>
|
||||
<Button Command="{Binding OpenPracticalDemoCmd}" DockPanel.Dock="Top" HorizontalAlignment="Stretch" Margin="10,10,10,4" Content="{ex:Lang Key={x:Static langs:LangKeys.PracticalDemos}}" BorderThickness="0" Background="{DynamicResource SecondaryRegionBrush}"/>
|
||||
<TabControl SelectionChanged="TabControl_OnSelectionChanged" ItemContainerStyle="{StaticResource TabItemTransparent}" ItemsSource="{Binding DemoInfoList}" Style="{StaticResource TabControlInLine}" Background="Transparent" SelectedIndex="0">
|
||||
<TabControl SelectionChanged="TabControl_OnSelectionChanged" ItemContainerStyle="{StaticResource TabItemTransparent}" ItemsSource="{Binding DemoInfoCollection}" Style="{StaticResource TabControlInLine}" Background="Transparent" SelectedIndex="0">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{ex:Lang Key={Binding Title}}"/>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<Border xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||
x:Class="HandyControlDemo.UserControl.MainContent">
|
||||
<Grid Name="GridMain" MinHeight="300" MinWidth="200" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
@@ -14,19 +13,7 @@
|
||||
<TextBlock Style="{StaticResource TextBlockDefault}" Foreground="White" Text="{Binding ContentTitle}"/>
|
||||
<ToggleButton Margin="0,0,6,0" IsChecked="{Binding IsOpen,ElementName=DrawerCode}" Padding="5" Foreground="{DynamicResource TextIconBrush}" Style="{StaticResource ToggleButtonIconTransparent}" HorizontalAlignment="Right" hc:IconElement.Geometry="{StaticResource CodeGeometry}"/>
|
||||
<hc:Drawer Name="DrawerCode" Opened="DrawerCode_OnOpened">
|
||||
<Border Style="{StaticResource BorderClip}" Margin="32,32,0,32" CornerRadius="10,0,0,10" Background="{DynamicResource RegionBrush}" Width="800">
|
||||
<TabControl Grid.Row="1" Style="{StaticResource TabControlInLine}">
|
||||
<TabItem Header="XAML">
|
||||
<avalonedit:TextEditor Style="{StaticResource TextEditorCustom}" SyntaxHighlighting="XML" Name="EditorXaml"/>
|
||||
</TabItem>
|
||||
<TabItem Header="C#">
|
||||
<avalonedit:TextEditor Style="{StaticResource TextEditorCustom}" SyntaxHighlighting="C#" Name="EditorCs"/>
|
||||
</TabItem>
|
||||
<TabItem Header="VM">
|
||||
<avalonedit:TextEditor Style="{StaticResource TextEditorCustom}" SyntaxHighlighting="C#" Name="EditorVm"/>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Border>
|
||||
<Border Style="{StaticResource BorderClip}" Margin="32,32,0,32" CornerRadius="10,0,0,10" Background="{DynamicResource RegionBrush}" Width="800" Name="BorderCode"/>
|
||||
</hc:Drawer>
|
||||
</hc:SimplePanel>
|
||||
</Border>
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Extension;
|
||||
using HandyControlDemo.Data;
|
||||
using HandyControlDemo.ViewModel;
|
||||
using ICSharpCode.AvalonEdit;
|
||||
using ICSharpCode.AvalonEdit.Highlighting;
|
||||
|
||||
|
||||
namespace HandyControlDemo.UserControl
|
||||
@@ -16,6 +21,10 @@ namespace HandyControlDemo.UserControl
|
||||
|
||||
private string _currentDemoKey;
|
||||
|
||||
private bool _drawerCodeUsed;
|
||||
|
||||
private Dictionary<string, TextEditor> _textEditor;
|
||||
|
||||
public MainContent()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -49,6 +58,53 @@ namespace HandyControlDemo.UserControl
|
||||
|
||||
private void DrawerCode_OnOpened(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!_drawerCodeUsed)
|
||||
{
|
||||
var textEditorCustomStyle = ResourceHelper.GetResource<Style>("TextEditorCustom");
|
||||
_textEditor = new Dictionary<string, TextEditor>
|
||||
{
|
||||
["XAML"] = new TextEditor
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML")
|
||||
},
|
||||
["C#"] = new TextEditor
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#")
|
||||
},
|
||||
["VM"] = new TextEditor
|
||||
{
|
||||
Style = textEditorCustomStyle,
|
||||
SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#")
|
||||
}
|
||||
};
|
||||
BorderCode.Child = new TabControl
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("TabControlInLine"),
|
||||
Items =
|
||||
{
|
||||
new TabItem
|
||||
{
|
||||
Header = "XAML",
|
||||
Content = _textEditor["XAML"]
|
||||
},
|
||||
new TabItem
|
||||
{
|
||||
Header = "C#",
|
||||
Content = _textEditor["C#"]
|
||||
},
|
||||
new TabItem
|
||||
{
|
||||
Header = "VM",
|
||||
Content = _textEditor["VM"]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_drawerCodeUsed = true;
|
||||
}
|
||||
|
||||
var typeKey = ViewModelLocator.Instance.Main.DemoInfoCurrent.Key;
|
||||
var demoKey = ViewModelLocator.Instance.Main.DemoItemCurrent.TargetCtlName;
|
||||
if (Equals(_currentDemoKey, demoKey)) return;
|
||||
@@ -64,9 +120,9 @@ namespace HandyControlDemo.UserControl
|
||||
? $"ViewModel/{dcTypeName}"
|
||||
: xamlPath;
|
||||
|
||||
EditorXaml.Text = DemoHelper.GetCode(xamlPath);
|
||||
EditorCs.Text = DemoHelper.GetCode($"{xamlPath}.cs");
|
||||
EditorVm.Text = DemoHelper.GetCode($"{vmPath}.cs");
|
||||
_textEditor["XAML"].Text = DemoHelper.GetCode(xamlPath);
|
||||
_textEditor["C#"].Text = DemoHelper.GetCode($"{xamlPath}.cs");
|
||||
_textEditor["VM"].Text = DemoHelper.GetCode($"{vmPath}.cs");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using HandyControl.Controls;
|
||||
@@ -26,11 +29,6 @@ namespace HandyControlDemo.ViewModel
|
||||
/// </summary>
|
||||
private object _subContent;
|
||||
|
||||
/// <summary>
|
||||
/// demo信息
|
||||
/// </summary>
|
||||
private List<DemoInfoModel> _demoInfoList;
|
||||
|
||||
#endregion
|
||||
|
||||
public MainViewModel(DataService dataService)
|
||||
@@ -42,12 +40,12 @@ namespace HandyControlDemo.ViewModel
|
||||
disposable.Dispose();
|
||||
}
|
||||
SubContent = obj;
|
||||
});
|
||||
}, true);
|
||||
|
||||
Messenger.Default.Register<object>(this, MessageToken.ClearLeftSelected, obj =>
|
||||
{
|
||||
DemoItemCurrent = null;
|
||||
foreach (var item in DemoInfoList)
|
||||
foreach (var item in DemoInfoCollection)
|
||||
{
|
||||
item.SelectedIndex = -1;
|
||||
}
|
||||
@@ -60,7 +58,31 @@ namespace HandyControlDemo.ViewModel
|
||||
});
|
||||
|
||||
DataList = dataService.GetDemoDataList();
|
||||
DemoInfoList = dataService.GetDemoInfo();
|
||||
DemoInfoCollection = new ObservableCollection<DemoInfoModel>();
|
||||
|
||||
#if netle40
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
foreach (var item in dataService.GetDemoInfo())
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
});
|
||||
#else
|
||||
Task.Run(() =>
|
||||
{
|
||||
foreach (var item in dataService.GetDemoInfo())
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
#region 属性
|
||||
@@ -101,15 +123,7 @@ namespace HandyControlDemo.ViewModel
|
||||
/// <summary>
|
||||
/// demo信息
|
||||
/// </summary>
|
||||
public List<DemoInfoModel> DemoInfoList
|
||||
{
|
||||
get => _demoInfoList;
|
||||
#if netle40
|
||||
set => Set(nameof(DemoInfoList), ref _demoInfoList, value);
|
||||
#else
|
||||
set => Set(ref _demoInfoList, value);
|
||||
#endif
|
||||
}
|
||||
public ObservableCollection<DemoInfoModel> DemoInfoCollection { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in new issue
Block a user