我正在尝试重现像系统画廊这样的画廊,但是我在缩放时遇到了问题,容器没有放大并且图片覆盖,我尝试与列表框一起使用:
<ListBox x:Name="pictureListBox" Margin="10,10,10,0" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Visible" VerticalAlignment="Top">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="3">
<StackPanel>
<Image x:Name="Image" Source="{Binding Source}" Width="400" Stretch="Uniform" Canvas.ZIndex="1">
<Image.RenderTransform>
<CompositeTransform x:Name="transform" />
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchStarted="OnPinchStarted" PinchDelta="OnPinchDelta" DragDelta="OnDragDelta" />
</toolkit:GestureService.GestureListener>
</Image>
</StackPanel>
<!--<Image Source="/Images/gallery_loading.jpg" Width="150" Height="150" Stretch="Uniform"/>-->
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和全景:
<phone:Panorama x:Name="panorama" Margin="0,0,0,0" ItemsSource="{Binding}" Width="550">
<phone:Panorama.HeaderTemplate>
<DataTemplate>
<TextBlock Text=""/>
</DataTemplate>
</phone:Panorama.HeaderTemplate>
<phone:Panorama.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Source}" Margin="5">
<Image.RenderTransform>
<CompositeTransform x:Name="transform" />
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchStarted="OnPinchStarted" PinchDelta="OnPinchDelta" DragDelta="OnDragDelta" />
</toolkit:GestureService.GestureListener>
</Image>
</DataTemplate>
</phone:Panorama.ItemTemplate>
</phone:Panorama>
这是c#代码:
Image image = null;
CompositeTransform transform = null;
private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
image = sender as Image;
transform = image.RenderTransform as CompositeTransform;
//initialAngle = transform.Rotation;
initialScale = transform.ScaleX;
}
private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
//transform.Rotation = initialAngle + e.TotalAngleDelta;
transform.ScaleX = initialScale * e.DistanceRatio;
transform.ScaleY = initialScale * e.DistanceRatio;
}
谢谢大家