chore: add Shortcut for demo.

This commit is contained in:
NaBian committed 2022-11-12 13:17:25 +08:00
1 parent d787654486
commit c07ad3f801
3 files changed
+29 -42

No files matched your search

@@ -27,7 +27,9 @@ public partial class MainWindow
GlobalShortcut.Init(new List<KeyBinding>
{
new(ViewModelLocator.Instance.Main.GlobalShortcutInfoCmd, Key.I, ModifierKeys.Control | ModifierKeys.Alt),
new(ViewModelLocator.Instance.Main.GlobalShortcutWarningCmd, Key.E, ModifierKeys.Control | ModifierKeys.Alt)
new(ViewModelLocator.Instance.Main.GlobalShortcutWarningCmd, Key.E, ModifierKeys.Control | ModifierKeys.Alt),
new(ViewModelLocator.Instance.Main.OpenDocCmd, Key.F1, ModifierKeys.None),
new(ViewModelLocator.Instance.Main.OpenCodeCmd, Key.F12, ModifierKeys.None)
});
Dialog.SetToken(this, MessageToken.MainWindow);
@@ -15,9 +15,9 @@
<hc:SimplePanel>
<hc:Watermark Mark="{Binding ContentTitle}" MarkMargin="3,0" FontSize="20" FontWeight="Bold" MarkBrush="#0F000000"/>
<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}"/>
<ToggleButton Margin="0,0,6,0" IsChecked="{Binding IsCodeOpening}" Padding="5" Foreground="{DynamicResource TextIconBrush}" Style="{StaticResource ToggleButtonIconTransparent}" HorizontalAlignment="Right" hc:IconElement.Geometry="{StaticResource CodeGeometry}"/>
<Button Command="{Binding OpenDocCmd}" Height="26" Width="30" Margin="6,0,0,0" Padding="5" Foreground="{DynamicResource TextIconBrush}" Style="{StaticResource ButtonIcon}" HorizontalAlignment="Left" hc:IconElement.Geometry="{StaticResource DocumentGeometry}"/>
<hc:Drawer Name="DrawerCode" Opened="DrawerCode_OnOpened">
<hc:Drawer Name="DrawerCode" Opened="DrawerCode_OnOpened" IsOpen="{Binding IsCodeOpening}">
<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>
@@ -18,22 +18,12 @@ namespace HandyControlDemo.ViewModel;
public class MainViewModel : DemoViewModelBase<DemoDataModel>
{
#region 字段
/// <summary>
/// 内容标题
/// </summary>
private object _contentTitle;
/// <summary>
/// 子内容
/// </summary>
private object _subContent;
private bool _isCodeOpened;
private readonly DataService _dataService;
#endregion
public MainViewModel(DataService dataService)
{
_dataService = dataService;
@@ -42,18 +32,10 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
UpdateLeftContent();
}
#region 属性
/// <summary>
/// 当前选中的demo项
/// </summary>
public DemoItemModel DemoItemCurrent { get; private set; }
public DemoInfoModel DemoInfoCurrent { get; set; }
/// <summary>
/// 子内容
/// </summary>
public object SubContent
{
get => _subContent;
@@ -64,9 +46,6 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
#endif
}
/// <summary>
/// 内容标题
/// </summary>
public object ContentTitle
{
get => _contentTitle;
@@ -77,18 +56,18 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
#endif
}
/// <summary>
/// demo信息
/// </summary>
public bool IsCodeOpened
{
get => _isCodeOpened;
#if NET40
set => Set(nameof(IsCodeOpened), ref _isCodeOpened, value);
#else
set => Set(ref _isCodeOpened, value);
#endif
}
public ObservableCollection<DemoInfoModel> DemoInfoCollection { get; set; }
#endregion
#region 命令
/// <summary>
/// 切换例子命令
/// </summary>
public RelayCommand<SelectionChangedEventArgs> SwitchDemoCmd => new(SwitchDemo);
public RelayCommand OpenPracticalDemoCmd => new(OpenPracticalDemo);
@@ -99,12 +78,23 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
public RelayCommand OpenDocCmd => new(() =>
{
if (DemoItemCurrent is null)
{
return;
}
ControlCommands.OpenLink.Execute(_dataService.GetDemoUrl(DemoInfoCurrent, DemoItemCurrent));
});
#endregion
public RelayCommand OpenCodeCmd => new(() =>
{
if (DemoItemCurrent is null)
{
return;
}
#region 方法
IsCodeOpened = !IsCodeOpened;
});
private void UpdateMainContent()
{
@@ -156,9 +146,6 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
});
}
/// <summary>
/// 切换例子
/// </summary>
private void SwitchDemo(SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 0) return;
@@ -185,6 +172,4 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
Messenger.Default.Send(true, MessageToken.FullSwitch);
}
#endregion
}