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
5b51700e
Commit
5b51700e
authored
Jan 01, 2022
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 Set1Behavior 行为
parent
de878a63
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
0 deletions
+146
-0
Set1Action.cs
Project.FLY.ControlLibrary/FLY.ControlLibrary/Set1Action.cs
+146
-0
No files found.
Project.FLY.ControlLibrary/FLY.ControlLibrary/Set1Action.cs
0 → 100644
View file @
5b51700e
using
Microsoft.Xaml.Behaviors
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Input
;
namespace
FLY.ControlLibrary
{
/// <summary>
/// 后台添加功能,按钮 click事件 属性=true
/// </summary>
public
class
Set1Action
:
IDisposable
{
/// <summary>
/// 对象
/// </summary>
public
object
obj
;
/// <summary>
/// bool 属性
/// </summary>
public
string
propertyname
;
/// <summary>
/// 按下时为 true
/// </summary>
public
bool
pressIsTrue
;
UIElement
uIElement
;
/// <summary>
///
/// </summary>
/// <param name="uIElement"></param>
/// <param name="obj"></param>
/// <param name="propertyname"></param>
public
Set1Action
(
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
Set1Action
(
UIElement
uIElement
,
string
propertyname
)
:
this
(
uIElement
,
null
,
propertyname
)
{
}
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
;
Misc
.
PropertiesManager
.
SetValue
(
obj
,
propertyname
,
true
);
}
}
/// <summary>
/// Set1Action 的 XAML 版 ,附加行为。
/// </summary>
public
class
Set1Behavior
:
Behavior
<
UIElement
>
{
public
System
.
Windows
.
Data
.
Binding
Binding
{
get
;
set
;
}
Set1Action
set1Action
=
null
;
public
Set1Behavior
()
{
}
protected
override
void
OnAttached
()
{
base
.
OnAttached
();
UIElement
dobj
=
AssociatedObject
;
if
(
Binding
!=
null
&&
Binding
.
Path
!=
null
)
{
if
(
Binding
.
Source
!=
null
)
{
set1Action
=
new
Set1Action
(
dobj
,
Binding
.
Source
,
Binding
.
Path
.
Path
);
}
else
{
var
obj
=
COMMON
.
GetDataContext
(
dobj
);
if
(
obj
==
null
)
{
set1Action
=
new
Set1Action
(
dobj
,
Binding
.
Path
.
Path
);
}
else
{
set1Action
=
new
Set1Action
(
dobj
,
obj
,
Binding
.
Path
.
Path
);
}
}
}
}
protected
override
void
OnDetaching
()
{
base
.
OnDetaching
();
if
(
set1Action
!=
null
)
{
set1Action
.
Dispose
();
set1Action
=
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