Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VIZ.Framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王永辉
VIZ.Framework
Commits
6f7d995a
Commit
6f7d995a
authored
Jul 27, 2022
by
liulongfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
热键输入框
parent
a51c3e62
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
276 additions
and
1 deletions
+276
-1
VIZ.Framework.Common/Themes/Generic.xaml
+1
-0
VIZ.Framework.Common/VIZ.Framework.Common.csproj
+7
-0
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyBox.cs
+79
-0
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyBox.xaml
+18
-0
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyHelper.cs
+106
-0
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyPropertyAttribute.cs
+16
-0
VIZ.Framework.WpfTest/HotkeyBoxTest/HotkeyBoxTest.xaml
+13
-0
VIZ.Framework.WpfTest/HotkeyBoxTest/HotkeyBoxTest.xaml.cs
+28
-0
VIZ.Framework.WpfTest/MainWindow.xaml
+1
-1
VIZ.Framework.WpfTest/VIZ.Framework.WpfTest.csproj
+7
-0
No files found.
VIZ.Framework.Common/Themes/Generic.xaml
View file @
6f7d995a
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/NumberBox/NumberBox.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/NumberBox/NumberBox.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/ColorPickButton/ColorPickButton.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/ColorPickButton/ColorPickButton.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/LabelValue/LabelValue.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/LabelValue/LabelValue.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/HotkeyBox/HotkeyBox.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary>
VIZ.Framework.Common/VIZ.Framework.Common.csproj
View file @
6f7d995a
...
@@ -138,6 +138,10 @@
...
@@ -138,6 +138,10 @@
<SubType>Designer</SubType>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:Compile</Generator>
</Page>
</Page>
<Page Include="Widgets\HotkeyBox\HotkeyBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widgets\LabelValue\LabelValue.xaml">
<Page Include="Widgets\LabelValue\LabelValue.xaml">
<SubType>Designer</SubType>
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:Compile</Generator>
...
@@ -233,6 +237,9 @@
...
@@ -233,6 +237,9 @@
<Compile Include="Widgets\ColorPickButton\ColorPickButton.cs" />
<Compile Include="Widgets\ColorPickButton\ColorPickButton.cs" />
<Compile Include="Widgets\DebugBorder\DebugBorder.cs" />
<Compile Include="Widgets\DebugBorder\DebugBorder.cs" />
<Compile Include="Widgets\DragWindowBar\DragWindowBar.cs" />
<Compile Include="Widgets\DragWindowBar\DragWindowBar.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyBox.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyHelper.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyPropertyAttribute.cs" />
<Compile Include="Widgets\LabelValue\LabelValue.cs" />
<Compile Include="Widgets\LabelValue\LabelValue.cs" />
<Compile Include="Widgets\NavigationControl\NavigationConfig.cs" />
<Compile Include="Widgets\NavigationControl\NavigationConfig.cs" />
<Compile Include="Widgets\NavigationControl\NavigationControl.cs" />
<Compile Include="Widgets\NavigationControl\NavigationControl.cs" />
...
...
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyBox.cs
0 → 100644
View file @
6f7d995a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
System.Windows.Documents
;
using
System.Windows.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
namespace
VIZ.Framework.Common
{
/// <summary>
/// 热键输入框
/// </summary>
[
TemplatePart
(
Name
=
nameof
(
PART_TextBox
),
Type
=
typeof
(
TextBox
))]
public
class
HotkeyBox
:
Control
{
static
HotkeyBox
()
{
DefaultStyleKeyProperty
.
OverrideMetadata
(
typeof
(
HotkeyBox
),
new
FrameworkPropertyMetadata
(
typeof
(
HotkeyBox
)));
}
/// <summary>
/// 输入框
/// </summary>
private
TextBox
PART_TextBox
;
#
region
Hotkey
--
热键
/// <summary>
/// 热键
/// </summary>
public
string
Hotkey
{
get
{
return
(
string
)
GetValue
(
HotkeyProperty
);
}
set
{
SetValue
(
HotkeyProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for Hotkey. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
HotkeyProperty
=
DependencyProperty
.
Register
(
"Hotkey"
,
typeof
(
string
),
typeof
(
HotkeyBox
),
new
PropertyMetadata
(
null
));
#
endregion
/// <summary>
/// 应用模板
/// </summary>
public
override
void
OnApplyTemplate
()
{
base
.
OnApplyTemplate
();
this
.
PART_TextBox
=
this
.
Template
.
FindName
(
nameof
(
this
.
PART_TextBox
),
this
)
as
TextBox
;
if
(
this
.
PART_TextBox
==
null
)
return
;
this
.
PART_TextBox
.
IsReadOnly
=
true
;
this
.
PART_TextBox
.
PreviewKeyDown
-=
PART_TextBox_PreviewKeyDown
;
this
.
PART_TextBox
.
PreviewKeyDown
+=
PART_TextBox_PreviewKeyDown
;
}
/// <summary>
/// 按钮按下
/// </summary>
private
void
PART_TextBox_PreviewKeyDown
(
object
sender
,
KeyEventArgs
e
)
{
e
.
Handled
=
true
;
this
.
Hotkey
=
HotkeyHelper
.
GetHotkey
(
e
);
}
}
}
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyBox.xaml
0 → 100644
View file @
6f7d995a
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VIZ.Framework.Common">
<Style TargetType="{x:Type local:HotkeyBox}">
<Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:HotkeyBox}">
<TextBox x:Name="PART_TextBox" IsReadOnly="True" AcceptsReturn="False" TextWrapping="NoWrap" VerticalContentAlignment="Center"
Text="{TemplateBinding Hotkey}"></TextBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
\ No newline at end of file
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyHelper.cs
0 → 100644
View file @
6f7d995a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Input
;
namespace
VIZ.Framework.Common
{
/// <summary>
/// 热键辅助类
/// </summary>
public
static
class
HotkeyHelper
{
/// <summary>
/// 获取热键值
/// </summary>
/// <param name="e">键盘事件</param>
/// <returns>热键值</returns>
public
static
string
GetHotkey
(
KeyEventArgs
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
// Ctl Alt Shift
if
(
e
.
KeyboardDevice
.
IsKeyDown
(
Key
.
LeftCtrl
)
||
e
.
KeyboardDevice
.
IsKeyDown
(
Key
.
RightCtrl
))
{
sb
.
Append
(
"Ctrl + "
);
}
if
(
e
.
KeyboardDevice
.
IsKeyDown
(
Key
.
LeftAlt
)
||
e
.
KeyboardDevice
.
IsKeyDown
(
Key
.
RightAlt
))
{
sb
.
Append
(
"Alt + "
);
}
if
(
e
.
KeyboardDevice
.
IsKeyDown
(
Key
.
LeftShift
)
||
e
.
KeyboardDevice
.
IsKeyDown
(
Key
.
RightShift
))
{
sb
.
Append
(
"Shift + "
);
}
// D0 - D9 A - Z
for
(
int
i
=
(
int
)
Key
.
D0
;
i
<=
(
int
)
Key
.
Z
;
i
++)
{
Key
key
=
(
Key
)
i
;
if
(
e
.
KeyboardDevice
.
IsKeyDown
(
key
))
{
sb
.
Append
(
$"
{
key
}
"
);
break
;
}
}
// F1 - F12
for
(
int
i
=
(
int
)
Key
.
F1
;
i
<=
(
int
)
Key
.
F12
;
i
++)
{
Key
key
=
(
Key
)
i
;
if
(
e
.
KeyboardDevice
.
IsKeyDown
(
key
))
{
sb
.
Append
(
$"
{
key
}
"
);
break
;
}
}
return
sb
.
ToString
();
}
/// <summary>
/// 获取热键值
/// </summary>
/// <param name="e">键盘事件</param>
/// <returns>热键值</returns>
public
static
string
GetHotkey
(
System
.
Windows
.
Forms
.
KeyEventArgs
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
if
(
e
.
Control
)
{
sb
.
Append
(
"Ctrl + "
);
}
if
(
e
.
Alt
)
{
sb
.
Append
(
"Alt + "
);
}
if
(
e
.
Shift
)
{
sb
.
Append
(
"Shift + "
);
}
// D0 - D9
if
(
e
.
KeyCode
>=
System
.
Windows
.
Forms
.
Keys
.
D0
&&
e
.
KeyCode
<=
System
.
Windows
.
Forms
.
Keys
.
D9
)
{
sb
.
Append
(
$"
{
e
.
KeyCode
}
"
);
return
sb
.
ToString
();
}
// A - Z
if
(
e
.
KeyCode
>=
System
.
Windows
.
Forms
.
Keys
.
A
&&
e
.
KeyCode
<=
System
.
Windows
.
Forms
.
Keys
.
Z
)
{
sb
.
Append
(
$"
{
e
.
KeyCode
}
"
);
return
sb
.
ToString
();
}
// F1 - F12
if
(
e
.
KeyCode
>=
System
.
Windows
.
Forms
.
Keys
.
F1
&&
e
.
KeyCode
<=
System
.
Windows
.
Forms
.
Keys
.
F12
)
{
sb
.
Append
(
$"
{
e
.
KeyCode
}
"
);
return
sb
.
ToString
();
}
return
sb
.
ToString
();
}
}
}
VIZ.Framework.Common/Widgets/HotkeyBox/HotkeyPropertyAttribute.cs
0 → 100644
View file @
6f7d995a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
VIZ.Framework.Common
{
/// <summary>
/// 热键属性
/// </summary>
[
AttributeUsage
(
AttributeTargets
.
Property
,
AllowMultiple
=
false
,
Inherited
=
true
)]
public
class
HotkeyPropertyAttribute
:
Attribute
{
}
}
VIZ.Framework.WpfTest/HotkeyBoxTest/HotkeyBoxTest.xaml
0 → 100644
View file @
6f7d995a
<UserControl x:Class="VIZ.Framework.WpfTest.HotkeyBoxTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VIZ.Framework.WpfTest"
xmlns:common="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<common:HotkeyBox Width="400" Height="40"></common:HotkeyBox>
</Grid>
</UserControl>
VIZ.Framework.WpfTest/HotkeyBoxTest/HotkeyBoxTest.xaml.cs
0 → 100644
View file @
6f7d995a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
System.Windows.Documents
;
using
System.Windows.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
namespace
VIZ.Framework.WpfTest
{
/// <summary>
/// HotkeyBoxTest.xaml 的交互逻辑
/// </summary>
public
partial
class
HotkeyBoxTest
:
UserControl
{
public
HotkeyBoxTest
()
{
InitializeComponent
();
}
}
}
VIZ.Framework.WpfTest/MainWindow.xaml
View file @
6f7d995a
...
@@ -8,6 +8,6 @@
...
@@ -8,6 +8,6 @@
mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None"
mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None"
Title="MainWindow" Height="800" Width="1200">
Title="MainWindow" Height="800" Width="1200">
<Grid>
<Grid>
<local:
NumberBoxTest></local:Number
BoxTest>
<local:
HotkeyBoxTest></local:Hotkey
BoxTest>
</Grid>
</Grid>
</Window>
</Window>
VIZ.Framework.WpfTest/VIZ.Framework.WpfTest.csproj
View file @
6f7d995a
...
@@ -99,6 +99,10 @@
...
@@ -99,6 +99,10 @@
<Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<SubType>Designer</SubType>
</ApplicationDefinition>
</ApplicationDefinition>
<Page Include="HotkeyBoxTest\HotkeyBoxTest.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<SubType>Designer</SubType>
...
@@ -107,6 +111,9 @@
...
@@ -107,6 +111,9 @@
<DependentUpon>App.xaml</DependentUpon>
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
<SubType>Code</SubType>
</Compile>
</Compile>
<Compile Include="HotkeyBoxTest\HotkeyBoxTest.xaml.cs">
<DependentUpon>HotkeyBoxTest.xaml</DependentUpon>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
<SubType>Code</SubType>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment