app.config建议把4.0.30319(Win8+带的版本)放在前面,优先匹配.NET 4.x。如果把2.0.50727放前面,控件会变成Win7样式。
引用
评论
Class MainWindow
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
Dim opendlg As New Microsoft.Win32.OpenFileDialog()
If opendlg.ShowDialog() Then
imagebox.Source = New BitmapImage(New Uri(opendlg.FileName))
End If
End Sub
Private Sub MainWindow_Drop(sender As Object, e As DragEventArgs) Handles Me.Drop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim filelist As String() = e.Data.GetData(DataFormats.FileDrop)
imagebox.Source = New BitmapImage(New Uri(filelist(0)))
End If
End Sub
End Class<window x:class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:picview" mc:ignorable="d" title="图片查看器" height="350" width="525" allowdrop="True">
<grid>
<button x:name="button" content="打开" horizontalalignment="Left" margin="10,10,0,0" verticalalignment="Top" width="75">
<image x:name="imagebox" margin="10,40,10,10">
</image></button></grid>
</window><?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup uselegacyv2runtimeactivationpolicy="true">
<supportedruntime version="v4.0.30319">
<supportedruntime version="v2.0.50727">
</supportedruntime></supportedruntime></startup>
</configuration>