feat: MyImage 控件

This commit is contained in:
tangge233
2024-10-01 23:12:40 +08:00
parent 76bf3c40d0
commit 94476384bd
5 changed files with 68 additions and 21 deletions
@@ -0,0 +1,7 @@
<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>
@@ -0,0 +1,32 @@
Public Class MyImage
'自定义属性
Public Uuid As Integer = GetUuid()
Private _Uri As String = ""
Public Property Source As String
Get
Return _Uri
End Get
Set(value As String)
_Uri = value
RefreshImage()
End Set
End Property '显示文本
Public Shared 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()
End If
End Sub)))
Public Sub RefreshImage()
If Me Is Nothing Then Exit Sub
Try
PanContent.Source = New MyBitmap(_Uri.ToString())
Catch ex As Exception
Log(ex, "刷新图片内容失败")
End Try
End Sub
End Class
@@ -64,6 +64,11 @@ Public Class MyBitmap
BitmapCache.Add(FilePathOrResourceName, Pic) BitmapCache.Add(FilePathOrResourceName, Pic)
End If End If
Else Else
Dim tempFile = PathTemp & "Cache\MyImage\" & GetHash(FilePathOrResourceName)
If FilePathOrResourceName.StartsWith("http") Then
NetDownload(FilePathOrResourceName, tempFile, True)
FilePathOrResourceName = tempFile
End If
'使用这种自己接管 FileStream 的方法加载才能解除文件占用 '使用这种自己接管 FileStream 的方法加载才能解除文件占用
Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open) Using InputStream As New FileStream(FilePathOrResourceName, FileMode.Open)
'判断是否为 WebP 文件头 '判断是否为 WebP 文件头
@@ -8,6 +8,7 @@
<StackPanel Name="PanMain" Margin="25,25,25,10" Grid.IsSharedSizeScope="True"> <StackPanel Name="PanMain" Margin="25,25,25,10" Grid.IsSharedSizeScope="True">
<StackPanel x:Name="PanCustom"> <StackPanel x:Name="PanCustom">
</StackPanel> </StackPanel>
<local:MyImage Source="https://cdn.modrinth.com/data/AANobbMI/295862f4724dc3f78df3447ad6072b2dcd3ef0c9_96.webp"/>
<local:MyCard Margin="0,0,0,15" Title="快照版提示" x:Name="PanHint"> <local:MyCard Margin="0,0,0,15" Title="快照版提示" x:Name="PanHint">
<local:MyIconButton LogoScale="1.1" Logo="F1 M2,0 L0,2 8,10 0,18 2,20 10,12 18,20 20,18 12,10 20,2 18,0 10,8 2,0Z" <local:MyIconButton LogoScale="1.1" Logo="F1 M2,0 L0,2 8,10 0,18 2,20 10,12 18,20 20,18 12,10 20,2 18,0 10,8 2,0Z"
Height="20" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Top" Height="20" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Top"
@@ -183,6 +183,9 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Controls\IMyRadio.vb" /> <Compile Include="Controls\IMyRadio.vb" />
<Compile Include="Controls\MyImage.xaml.vb">
<DependentUpon>MyImage.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\MyComboBox.vb" /> <Compile Include="Controls\MyComboBox.vb" />
<Compile Include="Controls\MyComboBoxItem.vb" /> <Compile Include="Controls\MyComboBoxItem.vb" />
<Compile Include="Controls\MyCard.vb" /> <Compile Include="Controls\MyCard.vb" />
@@ -191,9 +194,6 @@
<Compile Include="Controls\MyIconTextButton.xaml.vb"> <Compile Include="Controls\MyIconTextButton.xaml.vb">
<DependentUpon>MyIconTextButton.xaml</DependentUpon> <DependentUpon>MyIconTextButton.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Modules\Minecraft\ModComp.vb" /> <Compile Include="Modules\Minecraft\ModComp.vb" />
<Compile Include="Modules\Minecraft\ModJava.vb" /> <Compile Include="Modules\Minecraft\ModJava.vb" />
<Compile Include="Modules\Minecraft\ModMod.vb" /> <Compile Include="Modules\Minecraft\ModMod.vb" />
@@ -381,6 +381,10 @@
<Compile Include="Pages\PageSpeedRight.xaml.vb"> <Compile Include="Pages\PageSpeedRight.xaml.vb">
<DependentUpon>PageSpeedRight.xaml</DependentUpon> <DependentUpon>PageSpeedRight.xaml</DependentUpon>
</Compile> </Compile>
<Page Include="Controls\MyImage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\MyExtraButton.xaml"> <Page Include="Controls\MyExtraButton.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@@ -478,7 +482,6 @@
<DependentUpon>FormMain.xaml</DependentUpon> <DependentUpon>FormMain.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="Modules\Minecraft\MyLocalModItem.xaml"> <Page Include="Modules\Minecraft\MyLocalModItem.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -913,7 +916,6 @@
<Resource Include="Images\Heads\MCBBS.png" /> <Resource Include="Images\Heads\MCBBS.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="Images\Blocks\NeoForge.png" /> <Resource Include="Images\Blocks\NeoForge.png" />