Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
3cb0dbf0
Commit
3cb0dbf0
authored
Oct 31, 2021
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 FLY.ControlLibrary 添加 ToggleAction 动作行为 behavior
parent
993e371a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
167 additions
and
1 deletion
+167
-1
FLY.ControlLibrary.csproj
...ntrolLibrary/FLY.ControlLibrary/FLY.ControlLibrary.csproj
+1
-0
ResetAction.cs
Project.FLY.ControlLibrary/FLY.ControlLibrary/ResetAction.cs
+1
-1
ToggleAction.cs
...ect.FLY.ControlLibrary/FLY.ControlLibrary/ToggleAction.cs
+165
-0
No files found.
Project.FLY.ControlLibrary/FLY.ControlLibrary/FLY.ControlLibrary.csproj
View file @
3cb0dbf0
...
...
@@ -87,6 +87,7 @@
<Compile
Include=
"PieChart.xaml.cs"
>
<DependentUpon>
PieChart.xaml
</DependentUpon>
</Compile>
<Compile
Include=
"ToggleAction.cs"
/>
<Compile
Include=
"ResetAction.cs"
/>
<Compile
Include=
"UI.OSK\IVirtualKeyboard.cs"
/>
<Compile
Include=
"UI.OSK\KeyboardBehavior.cs"
/>
...
...
Project.FLY.ControlLibrary/FLY.ControlLibrary/ResetAction.cs
View file @
3cb0dbf0
...
...
@@ -136,7 +136,7 @@ namespace FLY.ControlLibrary
/// <summary>
/// ResetAction2 的 XAML 版 ,附加行为。
///
还没完成
///
与 NoToggleButton 控件 一起使用
/// </summary>
public
class
ResetBehavior
:
Behavior
<
UIElement
>
{
...
...
Project.FLY.ControlLibrary/FLY.ControlLibrary/ToggleAction.cs
0 → 100644
View file @
3cb0dbf0
using
Microsoft.Xaml.Behaviors
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Controls.Primitives
;
using
System.Windows.Input
;
namespace
FLY.ControlLibrary
{
/// <summary>
/// 后台添加功能,按钮按下 会切换 属性 状态, true变false,false 变true
/// </summary>
public
class
ToggleAction
:
IDisposable
{
/// <summary>
/// 对象
/// </summary>
public
object
obj
;
/// <summary>
/// bool 属性
/// </summary>
public
string
propertyname
;
UIElement
uIElement
;
/// <summary>
///
/// </summary>
/// <param name="uIElement"></param>
/// <param name="obj"></param>
/// <param name="propertyname"></param>
public
ToggleAction
(
UIElement
uIElement
,
object
obj
,
string
propertyname
)
{
this
.
uIElement
=
uIElement
;
this
.
obj
=
obj
;
this
.
propertyname
=
propertyname
;
uIElement
.
PreviewMouseDown
+=
UIElement_PreviewMouseDown
;
uIElement
.
PreviewTouchDown
+=
UIElement_PreviewTouchDown
;
}
/// <summary>
///
/// </summary>
/// <param name="uIElement"></param>
/// <param name="propertyname"></param>
public
ToggleAction
(
UIElement
uIElement
,
string
propertyname
)
:
this
(
uIElement
,
null
,
propertyname
)
{
}
/// <summary>
///
/// </summary>
public
void
Dispose
()
{
uIElement
.
PreviewMouseDown
-=
UIElement_PreviewMouseDown
;
uIElement
.
PreviewTouchDown
-=
UIElement_PreviewTouchDown
;
}
private
void
UIElement_PreviewTouchDown
(
object
sender
,
TouchEventArgs
e
)
{
Down
();
}
private
void
UIElement_PreviewMouseDown
(
object
sender
,
MouseButtonEventArgs
e
)
{
Down
();
}
bool
IsObjNull
()
{
if
(
obj
==
null
)
{
if
(
uIElement
is
FrameworkElement
)
{
obj
=
(
uIElement
as
FrameworkElement
).
DataContext
;
if
(
obj
==
null
)
return
true
;
}
else
{
return
true
;
}
}
return
false
;
}
void
Down
()
{
if
(
IsObjNull
())
return
;
var
value
=
Misc
.
PropertiesManager
.
GetValue
(
obj
,
propertyname
);
var
v
=
(
bool
)
value
;
if
(
v
)
Misc
.
PropertiesManager
.
SetValue
(
obj
,
propertyname
,
false
);
else
Misc
.
PropertiesManager
.
SetValue
(
obj
,
propertyname
,
true
);
}
}
/// <summary>
/// ToggleAction 的 XAML 版 ,附加行为。
/// 与 NoToggleButton 控件 一起使用
/// </summary>
public
class
ToggleBehavior
:
Behavior
<
UIElement
>
{
/// <summary>
///
/// </summary>
public
System
.
Windows
.
Data
.
Binding
Binding
{
get
;
set
;
}
ToggleAction
toggleAction
=
null
;
/// <summary>
///
/// </summary>
public
ToggleBehavior
()
{
}
/// <summary>
///
/// </summary>
protected
override
void
OnAttached
()
{
base
.
OnAttached
();
UIElement
dobj
=
AssociatedObject
;
if
(
Binding
!=
null
&&
Binding
.
Path
!=
null
)
{
if
(
Binding
.
Source
!=
null
)
{
toggleAction
=
new
ToggleAction
(
dobj
,
Binding
.
Source
,
Binding
.
Path
.
Path
);
}
else
{
var
obj
=
COMMON
.
GetDataContext
(
dobj
);
if
(
obj
==
null
)
{
toggleAction
=
new
ToggleAction
(
dobj
,
Binding
.
Path
.
Path
);
}
else
{
toggleAction
=
new
ToggleAction
(
dobj
,
obj
,
Binding
.
Path
.
Path
);
}
}
}
}
/// <summary>
///
/// </summary>
protected
override
void
OnDetaching
()
{
base
.
OnDetaching
();
if
(
toggleAction
!=
null
)
{
toggleAction
.
Dispose
();
toggleAction
=
null
;
}
}
}
}
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