feat: 修改实现方式

This commit is contained in:
tangge233
2024-10-02 12:07:42 +08:00
parent 805a0e1544
commit a6aa7847c0
4 changed files with 44 additions and 48 deletions
@@ -1,32 +1,34 @@
Public Class MyImage
Inherits Image
'事件
'自定义属性
Public Uuid As Integer = GetUuid()
Private _Uri As String = ""
Public Property Source As String
Private _SourceData As String = ""
''' <summary>
''' 重写Image的Source属性
''' </summary>
Public Shadows Property Source As String
Get
Return _Uri
Return _SourceData
End Get
Set(value As String)
_Uri = value
RefreshImage()
SetImage(value)
End Set
End Property '显示文本
Public Shared ReadOnly SourceProperty As DependencyProperty = DependencyProperty.Register("Source", GetType(String), GetType(MyImage), New PropertyMetadata(New PropertyChangedCallback(
End Property
Public Shared Shadows ReadOnly SourceProperty As DependencyProperty = DependencyProperty.Register("Source", GetType(String), GetType(MyImage), New PropertyMetadata(New PropertyChangedCallback(
Sub(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
If Not IsNothing(sender) Then
CType(sender, MyImage)._Uri = e.NewValue.ToString()
CType(sender, MyImage).RefreshImage()
CType(sender, MyImage).SetImage(e.NewValue)
End If
End Sub)))
Public Sub RefreshImage()
Private Sub SetImage(source As String)
If Me Is Nothing Then Exit Sub
Try
PanContent.Source = New MyBitmap(_Uri.ToString())
Catch ex As Exception
Log(ex, "刷新图片内容失败")
End Try
If String.IsNullOrEmpty(source) Then Exit Sub
_SourceData = source
MyBase.Source = New MyBitmap(_SourceData)
End Sub
End Class
@@ -1,7 +0,0 @@
<Border x:Class="MyImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FocusVisualStyle="{x:Null}" x:Name="PanBack"
ClipToBounds="True" UseLayoutRounding="False" SnapsToDevicePixels="False" Background="{StaticResource ColorBrushSemiTransparent}">
<Image x:Name="PanContent"/>
</Border>