在我的ModelView中,我有一个ObservableCollection of BitmapImages,它显示在我视图的列表框中。我正在尝试旋转ObservableCollection中的选定图像。
好的,弄清楚了,如果有什么东西看起来很愚蠢,你可以告诉我
//Create a transform
TransformedBitmap tBmp = new TransformedBitmap();
tBmp.BeginInit();
//Set the source = to the image currently selected
tBmp.Source = _Scans[_selectedImage].MyImage;
RotateTransform rt = new RotateTransform(180);
tBmp.Transform = rt;
tBmp.EndInit();
//Create a new source after the transform
BitmapSource s1 = tBmp;
BitmapImage bi = BitmapSourceToBitmapImage(s1);
//Add create the item and replace the current item in the collection
//edited according to comment
//ScannedImages s = new ScannedImages();
//s.MyImage = bi;
//_Scans[_selectedImage] = s;
Scans[_selectedImage].MyImage = BitmapSourceToBitmapImage(s1);
在DateTemplate中定义要如何显示图像(作为ListBox项(,可以使用.RenderTransform
属性转换/旋转控件。
按钮示例:
<Button
<Button.RenderTransform>
<RotateTransform CenterX="0" CenterY="0" Angle="45"/>
</Button.RenderTransform>
Test</Button>
阅读更多关于如何旋转对象的内容?MSDN文章