【发布时间】:2014-07-28 02:18:53
【问题描述】:
首先,我想澄清一下我是德国人,所以请不要介意我犯的一些语法错误。
我的问题是我想使用 XAML 代码旋转 WPF 中的 Image-Control 中显示的位图:
<Image Name="ImgDisp" Grid.ColumnSpan="4" Margin="10,2,10,10" Grid.Row="3" Grid.RowSpan="2" >
<Image.Source>
<TransformedBitmap Source="{Binding Path=CurrentImage}" >
<TransformedBitmap.Transform>
<RotateTransform Angle="90"/>
</TransformedBitmap.Transform>
</TransformedBitmap>
</Image.Source>
</Image>
属性绑定的类如下所示:
Public Class PropertyClass
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Dim _currentImage As String = ""
Public Property CurrentImage As String
Get
Return If(File.Exists(_currentImage), _currentImage, "")
End Get
Set(value As String)
_currentImage = value
CurrentImageName = New FileInfo(value).Name
NotifyPropertyChanged("CurrentImage")
End Set
End Property
Private Shared _instance As PropertyClass
Public Shared ReadOnly Property Instance As PropertyClass
Get
If _instance Is Nothing Then _instance = New PropertyClass
Return _instance
End Get
End Property
End Class
我得到的错误:
“System.Windows.Markup.XamlParseException”类型的第一次机会异常发生在 >PresentationFramework.dll
附加信息:Zeilennummer "97" und Zeilenposition "42" von "Bei der >Initialisierung von "System.Windows.Media.Imaging.TransformedBitmap" wurde eine Ausnahme >ausgelöst."。
这里有什么问题?非常感谢您的帮助,我对这个问题感到非常恼火。
【问题讨论】:
-
您需要将其绑定到带有项目中图像的相对路径而不是文件名的字符串。还要确保在您的项目中添加了图像文件,并且该文件的
BuildAction设置为Resource。 -
这样做的问题是用户更改了图像控件中的图像,因此将其放入资源中是不可能的。我用项目中的图像对其进行了测试,它可以工作!问题是如何使用图像的文件路径实现这种行为?