Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
HandyControl
提交
b818e7a4
H
HandyControl
项目概览
jobily
/
HandyControl
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
HandyControl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b818e7a4
编写于
1月 06, 2023
作者:
N
NaBian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enhance: add uri prop for ImageViewer.
上级
0ecbd4fd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
29 deletion
+81
-29
src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs
src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs
+81
-29
未找到文件。
src/Shared/HandyControl_Shared/Controls/Image/ImageViewer.cs
浏览文件 @
b818e7a4
...
...
@@ -195,20 +195,7 @@ public class ImageViewer : Control
/// <param name="uri"></param>
public
ImageViewer
(
Uri
uri
)
:
this
()
{
try
{
ImageSource
=
BitmapFrame
.
Create
(
uri
);
ImgPath
=
uri
.
AbsolutePath
;
if
(
File
.
Exists
(
ImgPath
))
{
var
info
=
new
FileInfo
(
ImgPath
);
ImgSize
=
info
.
Length
;
}
}
catch
{
MessageBox
.
Show
(
Lang
.
ErrorImgPath
);
}
Uri
=
uri
;
}
/// <summary>
...
...
@@ -229,11 +216,8 @@ public class ImageViewer : Control
public
static
readonly
DependencyProperty
ImageSourceProperty
=
DependencyProperty
.
Register
(
nameof
(
ImageSource
),
typeof
(
BitmapFrame
),
typeof
(
ImageViewer
),
new
PropertyMetadata
(
default
(
BitmapFrame
),
OnImageSourceChanged
));
private
static
void
OnImageSourceChanged
(
DependencyObject
d
,
DependencyPropertyChangedEventArgs
e
)
{
var
ctl
=
(
ImageViewer
)
d
;
ctl
.
Init
();
}
public
static
readonly
DependencyProperty
UriProperty
=
DependencyProperty
.
Register
(
nameof
(
Uri
),
typeof
(
Uri
),
typeof
(
ImageViewer
),
new
PropertyMetadata
(
default
(
Uri
),
OnUriChanged
));
public
static
readonly
DependencyProperty
ShowToolBarProperty
=
DependencyProperty
.
Register
(
nameof
(
ShowToolBar
),
typeof
(
bool
),
typeof
(
ImageViewer
),
new
PropertyMetadata
(
ValueBoxes
.
TrueBox
));
...
...
@@ -250,15 +234,9 @@ public class ImageViewer : Control
internal
static
readonly
DependencyProperty
ImgSizeProperty
=
DependencyProperty
.
Register
(
nameof
(
ImgSize
),
typeof
(
long
),
typeof
(
ImageViewer
),
new
PropertyMetadata
(-
1L
));
/// <summary>
/// 是否显示全屏按钮
/// </summary>
internal
static
readonly
DependencyProperty
ShowFullScreenButtonProperty
=
DependencyProperty
.
Register
(
nameof
(
ShowFullScreenButton
),
typeof
(
bool
),
typeof
(
ImageViewer
),
new
PropertyMetadata
(
ValueBoxes
.
FalseBox
));
/// <summary>
/// 关闭按钮是否显示中
/// </summary>
internal
static
readonly
DependencyProperty
ShowCloseButtonProperty
=
DependencyProperty
.
Register
(
nameof
(
ShowCloseButton
),
typeof
(
bool
),
typeof
(
ImageViewer
),
new
PropertyMetadata
(
ValueBoxes
.
FalseBox
));
...
...
@@ -312,6 +290,12 @@ public class ImageViewer : Control
set
=>
SetValue
(
ImageSourceProperty
,
value
);
}
public
Uri
Uri
{
get
=>
(
Uri
)
GetValue
(
UriProperty
);
set
=>
SetValue
(
UriProperty
,
value
);
}
public
bool
ShowToolBar
{
get
=>
(
bool
)
GetValue
(
ShowToolBarProperty
);
...
...
@@ -515,19 +499,19 @@ public class ImageViewer : Control
_imgWidHeiScale
=
width
/
height
;
var
scaleWindow
=
ActualWidth
/
ActualHeight
;
ImageScale
=
1
;
if
(
_imgWidHeiScale
>
scaleWindow
)
{
if
(
width
>
ActualWidth
)
{
ImageScale
=
ActualWidth
/
width
;
}
}
else
if
(
height
>
ActualHeight
)
{
ImageScale
=
ActualHeight
/
height
;
}
else
{
ImageScale
=
1
;
}
ImageMargin
=
new
Thickness
((
ActualWidth
-
ImageWidth
)
/
2
,
(
ActualHeight
-
ImageHeight
)
/
2
,
0
,
0
);
...
...
@@ -955,4 +939,72 @@ public class ImageViewer : Control
_mouseMoveBinding
=
new
MouseBinding
(
ControlCommands
.
MouseMove
,
newValue
);
InputBindings
.
Add
(
_mouseMoveBinding
);
}
private
static
void
OnImageSourceChanged
(
DependencyObject
d
,
DependencyPropertyChangedEventArgs
e
)
{
((
ImageViewer
)
d
).
OnImageSourceChanged
();
}
private
void
OnImageSourceChanged
()
{
Init
();
}
private
static
void
OnUriChanged
(
DependencyObject
d
,
DependencyPropertyChangedEventArgs
e
)
{
var
self
=
(
ImageViewer
)
d
;
if
(
e
.
NewValue
is
Uri
uri
)
{
self
.
ImageSource
=
GetBitmapFrame
(
uri
);
self
.
Init
();
}
else
{
self
.
ImageSource
=
null
;
}
static
BitmapFrame
GetBitmapFrame
(
Uri
source
)
{
try
{
return
BitmapFrame
.
Create
(
source
);
}
catch
{
return
null
;
}
}
}
private
void
OnUriChanged
(
Uri
newValue
)
{
if
(
newValue
is
not
null
)
{
ImageSource
=
GetBitmapFrame
(
newValue
);
ImgPath
=
newValue
.
AbsolutePath
;
if
(
File
.
Exists
(
ImgPath
))
{
ImgSize
=
new
FileInfo
(
ImgPath
).
Length
;
}
}
else
{
ImageSource
=
null
;
ImgPath
=
string
.
Empty
;
}
static
BitmapFrame
GetBitmapFrame
(
Uri
source
)
{
try
{
return
BitmapFrame
.
Create
(
source
);
}
catch
{
return
null
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录