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
739806e9
Commit
739806e9
authored
Jan 12, 2023
by
liulongfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
可缩放图片控件
parent
f1410da2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
214 additions
and
0 deletions
+214
-0
VIZ.Framework.Common/Themes/Generic.xaml
+1
-0
VIZ.Framework.Common/VIZ.Framework.Common.csproj
+5
-0
VIZ.Framework.Common/Widgets/ResizeImageControl/ResizeImageControl.cs
+185
-0
VIZ.Framework.Common/Widgets/ResizeImageControl/ResizeImageControl.xaml
+23
-0
No files found.
VIZ.Framework.Common/Themes/Generic.xaml
View file @
739806e9
...
...
@@ -13,6 +13,7 @@
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/HotkeyBox/HotkeyBox.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/GPIOPinTestControl/GPIOPinTestControl.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/ShowMessageControl/ShowMessageControl.xaml"></ResourceDictionary>
<ResourceDictionary Source="/VIZ.Framework.Common;component/Widgets/ResizeImageControl/ResizeImageControl.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
VIZ.Framework.Common/VIZ.Framework.Common.csproj
View file @
739806e9
...
...
@@ -182,6 +182,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widgets\ResizeImageControl\ResizeImageControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widgets\ShowMessageControl\ShowMessageControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
...
...
@@ -320,6 +324,7 @@
<Compile Include="Widgets\NavigationControl\NavigationControl.cs" />
<Compile Include="Widgets\NavigationControl\NavigationItemControl.cs" />
<Compile Include="Widgets\NoneWindow\NoneWindow.cs" />
<Compile Include="Widgets\ResizeImageControl\ResizeImageControl.cs" />
<Compile Include="Widgets\ShowMessageControl\ShowMessage.cs" />
<Compile Include="Widgets\ShowMessageControl\ShowMessageControl.cs" />
<Compile Include="Widgets\TimeDisplayControl\TimeDisplayControl.cs" />
...
...
VIZ.Framework.Common/Widgets/ResizeImageControl/ResizeImageControl.cs
0 → 100644
View file @
739806e9
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>
public
class
ResizeImageControl
:
Control
{
static
ResizeImageControl
()
{
DefaultStyleKeyProperty
.
OverrideMetadata
(
typeof
(
ResizeImageControl
),
new
FrameworkPropertyMetadata
(
typeof
(
ResizeImageControl
)));
}
public
ResizeImageControl
()
{
this
.
SizeChanged
+=
ResizeImageControl_SizeChanged
;
}
#
region
ImageSource
--
图片源
/// <summary>
/// 图片源
/// </summary>
public
ImageSource
ImageSource
{
get
{
return
(
ImageSource
)
GetValue
(
ImageSourceProperty
);
}
set
{
SetValue
(
ImageSourceProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for ImageSource. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
ImageSourceProperty
=
DependencyProperty
.
Register
(
"ImageSource"
,
typeof
(
ImageSource
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
null
));
#
endregion
#
region
IconSource
--
图标源
/// <summary>
/// 图标源
/// </summary>
public
ImageSource
IconSource
{
get
{
return
(
ImageSource
)
GetValue
(
IconSourceProperty
);
}
set
{
SetValue
(
IconSourceProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for IconSource. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
IconSourceProperty
=
DependencyProperty
.
Register
(
"IconSource"
,
typeof
(
ImageSource
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
null
));
#
endregion
#
region
ShowImageMinWidth
--
显示图片的最小宽度
/// <summary>
/// 显示图片的最小宽度
/// </summary>
public
double
ShowImageMinWidth
{
get
{
return
(
double
)
GetValue
(
ShowImageMinWidthProperty
);
}
set
{
SetValue
(
ShowImageMinWidthProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for ShowImageMinWidth. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
ShowImageMinWidthProperty
=
DependencyProperty
.
Register
(
"ShowImageMinWidth"
,
typeof
(
double
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
20d
));
#
endregion
#
region
ShowImageMinHeight
--
显示图片的最小高度
/// <summary>
/// 显示图片的最小高度
/// </summary>
public
double
ShowImageMinHeight
{
get
{
return
(
double
)
GetValue
(
ShowImageMinHeightProperty
);
}
set
{
SetValue
(
ShowImageMinHeightProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for ShowImageMinHeight. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
ShowImageMinHeightProperty
=
DependencyProperty
.
Register
(
"ShowImageMinHeight"
,
typeof
(
double
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
20d
));
#
endregion
#
region
ImageVisibility
--
图片可见性
/// <summary>
/// 图片可见性
/// </summary>
public
Visibility
ImageVisibility
{
get
{
return
(
Visibility
)
GetValue
(
ImageVisibilityProperty
);
}
set
{
SetValue
(
ImageVisibilityProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for ImageVisibility. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
ImageVisibilityProperty
=
DependencyProperty
.
Register
(
"ImageVisibility"
,
typeof
(
Visibility
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
Visibility
.
Hidden
));
#
endregion
#
region
IconVisibility
--
图标可见性
/// <summary>
/// 图标可见性
/// </summary>
public
Visibility
IconVisibility
{
get
{
return
(
Visibility
)
GetValue
(
IconVisibilityProperty
);
}
set
{
SetValue
(
IconVisibilityProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for IconVisibility. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
IconVisibilityProperty
=
DependencyProperty
.
Register
(
"IconVisibility"
,
typeof
(
Visibility
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
Visibility
.
Hidden
));
#
endregion
#
region
AspectRatio
--
宽高比
/// <summary>
/// 宽高比
/// </summary>
public
double
AspectRatio
{
get
{
return
(
double
)
GetValue
(
AspectRatioProperty
);
}
set
{
SetValue
(
AspectRatioProperty
,
value
);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for AspectRatio. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty
AspectRatioProperty
=
DependencyProperty
.
Register
(
"AspectRatio"
,
typeof
(
double
),
typeof
(
ResizeImageControl
),
new
PropertyMetadata
(
16d
/
9d
));
#
endregion
/// <summary>
/// 大小改变时触发
/// </summary>
private
void
ResizeImageControl_SizeChanged
(
object
sender
,
SizeChangedEventArgs
e
)
{
if
(
e
.
NewSize
.
Width
<
this
.
ShowImageMinWidth
||
e
.
NewSize
.
Height
<
this
.
ShowImageMinHeight
)
{
this
.
ImageVisibility
=
Visibility
.
Hidden
;
this
.
IconVisibility
=
Visibility
.
Visible
;
}
else
{
this
.
ImageVisibility
=
Visibility
.
Visible
;
this
.
IconVisibility
=
Visibility
.
Hidden
;
}
this
.
Height
=
e
.
NewSize
.
Width
/
this
.
AspectRatio
;
}
}
}
VIZ.Framework.Common/Widgets/ResizeImageControl/ResizeImageControl.xaml
0 → 100644
View file @
739806e9
<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:ResizeImageControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ResizeImageControl}">
<Grid Background="{TemplateBinding Background}">
<Image Source="{Binding Path=IconSource,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:ResizeImageControl}},Mode=OneWay}"
Visibility="{Binding Path=IconVisibility,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:ResizeImageControl}},Mode=OneWay}"
VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3"></Image>
<Image Source="{Binding Path=ImageSource,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:ResizeImageControl}},Mode=OneWay}"
Visibility="{Binding Path=ImageVisibility,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:ResizeImageControl}},Mode=OneWay}"
VerticalAlignment="Center" HorizontalAlignment="Center" Width="20" Height="20"></Image>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
\ No newline at end of file
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