This commit is contained in:
NaBian committed 2020-02-15 19:39:53 +08:00
1 parent d9b94f83fe
commit 7f0330856d
20 files changed
+1159 -52

No files matched your search

@@ -5,6 +5,8 @@ namespace HandyControlDemo.Data
{
public class DemoInfoModel : ViewModelBase
{
public string Key { get; set; }
private string _title;
public string Title
@@ -35,7 +35,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\StringRepeatConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\AssemblyHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\CommonHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ExternDllHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\Win32Helper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Basic\Avatar.xaml.cs">
<DependentUpon>Avatar.xaml</DependentUpon>
@@ -373,10 +373,12 @@ namespace HandyControlDemo.Service
var jsonObj = JsonConvert.DeserializeObject<dynamic>(jsonStr);
foreach (var item in jsonObj)
{
var title = Properties.Langs.Lang.ResourceManager.GetString((string)item.title);
var titleKey = (string) item.title;
var title = Properties.Langs.Lang.ResourceManager.GetString(titleKey);
var list = Convert2DemoItemList(item.demoItemList);
infoList.Add(new DemoInfoModel
{
Key = titleKey,
Title = title,
DemoItemList = list
});
@@ -1,12 +0,0 @@
using System.Runtime.InteropServices;
namespace HandyControlDemo.Tools
{
internal class ExternDllHelper
{
private const string Winmm = "winmm.dll";
[DllImport(Winmm, EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int MciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
}
}
@@ -7,5 +7,8 @@ namespace HandyControlDemo.Tools
{
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int MciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
}
}
@@ -5,6 +5,7 @@ using System.Windows.Controls.Primitives;
using HandyControl.Data;
using HandyControl.Tools.Extension;
using HandyControlDemo.Data;
using HandyControlDemo.ViewModel;
namespace HandyControlDemo.UserControl
@@ -24,6 +25,7 @@ namespace HandyControlDemo.UserControl
if (e.AddedItems.Count == 0) return;
if (e.AddedItems[0] is DemoInfoModel demoInfo)
{
ViewModelLocator.Instance.Main.DemoInfoCurrent = demoInfo;
var selectedIndex = demoInfo.SelectedIndex;
demoInfo.SelectedIndex = -1;
demoInfo.SelectedIndex = selectedIndex;
@@ -1,5 +1,7 @@
<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"
Background="{DynamicResource MainContentBackgroundBrush}">
<Border Background="{DynamicResource MainContentForegroundDrawingBrush}">
@@ -10,7 +12,25 @@
</Grid.RowDefinitions>
<Border Name="BorderEffect" Grid.RowSpan="2" Background="{DynamicResource RegionBrush}" CornerRadius="10" Effect="{StaticResource EffectShadow4}"/>
<Border Height="32" Name="BorderTitle" Grid.Row="0" CornerRadius="10,10,0,0" Background="{DynamicResource TitleBrush}">
<TextBlock Style="{StaticResource TextBlockDefault}" Foreground="White" Text="{Binding ContentTitle}"/>
<hc:SimplePanel>
<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 IsReadOnly="True" FontFamily="Consolas" Background="{DynamicResource RegionBrush}" SyntaxHighlighting="XML" Name="EditorXaml" Margin="4" ShowLineNumbers="True"/>
</TabItem>
<TabItem Header="C#">
<avalonedit:TextEditor IsReadOnly="True" FontFamily="Consolas" Background="{DynamicResource RegionBrush}" SyntaxHighlighting="C#" Name="EditorCs" Margin="4" ShowLineNumbers="True"/>
</TabItem>
<TabItem Header="VM">
<avalonedit:TextEditor IsReadOnly="True" FontFamily="Consolas" Background="{DynamicResource RegionBrush}" SyntaxHighlighting="C#" Name="EditorVm" Margin="4" ShowLineNumbers="True"/>
</TabItem>
</TabControl>
</Border>
</hc:Drawer>
</hc:SimplePanel>
</Border>
<Border Grid.Row="1" ClipToBounds="True">
<ContentPresenter Name="PresenterMain" Margin="0,0,0,10" Content="{Binding SubContent}"/>
@@ -2,6 +2,7 @@
using GalaSoft.MvvmLight.Messaging;
using HandyControl.Tools.Extension;
using HandyControlDemo.Data;
using HandyControlDemo.ViewModel;
namespace HandyControlDemo.UserControl
@@ -13,6 +14,8 @@ namespace HandyControlDemo.UserControl
{
private bool _isFull;
private string _currentDemoKey;
public MainContent()
{
InitializeComponent();
@@ -43,5 +46,25 @@ namespace HandyControlDemo.UserControl
PresenterMain.Margin = new Thickness(0, 0, 0, 10);
}
}
private void DrawerCode_OnOpened(object sender, RoutedEventArgs e)
{
var typeKey = ViewModelLocator.Instance.Main.DemoInfoCurrent.Key;
var demoKey = ViewModelLocator.Instance.Main.DemoItemCurrent.TargetCtlName;
if (Equals(_currentDemoKey, demoKey)) return;
_currentDemoKey = demoKey;
if (ViewModelLocator.Instance.Main.SubContent is FrameworkElement demoCtl)
{
var xamlPath = $"UserControl/{typeKey}/{demoCtl.GetType().Name}.xaml";
var dc = demoCtl.DataContext;
var dcTypeName = dc.GetType().Name;
var vmPath = $"ViewModel/{dcTypeName}";
EditorXaml.Text = DemoHelper.GetCode(xamlPath);
EditorCs.Text = DemoHelper.GetCode($"{xamlPath}.cs");
EditorVm.Text = DemoHelper.GetCode($"{vmPath}.cs");
}
}
}
}
@@ -104,12 +104,12 @@ namespace HandyControlDemo.ViewModel
private void StartRecord()
{
ExternDllHelper.MciSendString("set wave bitpersample 8", "", 0, 0);
ExternDllHelper.MciSendString("set wave samplespersec 20000", "", 0, 0);
ExternDllHelper.MciSendString("set wave channels 2", "", 0, 0);
ExternDllHelper.MciSendString("set wave format tag pcm", "", 0, 0);
ExternDllHelper.MciSendString("open new type WAVEAudio alias movie", "", 0, 0);
ExternDllHelper.MciSendString("record movie", "", 0, 0);
Win32Helper.MciSendString("set wave bitpersample 8", "", 0, 0);
Win32Helper.MciSendString("set wave samplespersec 20000", "", 0, 0);
Win32Helper.MciSendString("set wave channels 2", "", 0, 0);
Win32Helper.MciSendString("set wave format tag pcm", "", 0, 0);
Win32Helper.MciSendString("open new type WAVEAudio alias movie", "", 0, 0);
Win32Helper.MciSendString("record movie", "", 0, 0);
_stopwatch.Reset();
_stopwatch.Start();
@@ -135,9 +135,9 @@ namespace HandyControlDemo.ViewModel
var cachePath = $"{AudioCachePath}\\{Guid.NewGuid().ToString()}";
var cachePathWithQuotes = $"\"{cachePath}\"";
ExternDllHelper.MciSendString("stop movie", "", 0, 0);
ExternDllHelper.MciSendString($"save movie {cachePathWithQuotes}", "", 0, 0);
ExternDllHelper.MciSendString("close movie", "", 0, 0);
Win32Helper.MciSendString("stop movie", "", 0, 0);
Win32Helper.MciSendString($"save movie {cachePathWithQuotes}", "", 0, 0);
Win32Helper.MciSendString("close movie", "", 0, 0);
_stopwatch.Stop();
@@ -34,11 +34,6 @@ namespace HandyControlDemo.ViewModel
/// </summary>
private List<DemoInfoModel> _demoInfoList;
/// <summary>
/// 当前选中的demo项
/// </summary>
private DemoItemModel _demoItemCurrent;
#endregion
public MainViewModel(DataService dataService)
@@ -54,7 +49,7 @@ namespace HandyControlDemo.ViewModel
Messenger.Default.Register<object>(this, MessageToken.ClearLeftSelected, obj =>
{
_demoItemCurrent = null;
DemoItemCurrent = null;
foreach (var item in DemoInfoList)
{
item.SelectedIndex = -1;
@@ -67,6 +62,13 @@ namespace HandyControlDemo.ViewModel
#region 属性
/// <summary>
/// 当前选中的demo项
/// </summary>
public DemoItemModel DemoItemCurrent { get; private set; }
public DemoInfoModel DemoInfoCurrent { get; set; }
/// <summary>
/// 子内容
/// </summary>
@@ -141,9 +143,9 @@ namespace HandyControlDemo.ViewModel
if (e.AddedItems.Count == 0) return;
if (e.AddedItems[0] is DemoItemModel item)
{
if (Equals(_demoItemCurrent, item)) return;
if (Equals(DemoItemCurrent, item)) return;
_demoItemCurrent = item;
DemoItemCurrent = item;
ContentTitle = item.Name;
var obj = AssemblyHelper.ResolveByKey(item.TargetCtlName);
var ctl = obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");