xamarin 在转盘视图中缩放图像并滑动到下一张图像后,上一张图像不会以其原始形式显示,而是以缩放类型图像显示

0wi1tuuw  于 2023-02-01  发布在  其他
关注(0)|答案(1)|浏览(243)

在旋转木马视图中缩放图像并将图像滑动到其他图像,然后返回到我缩放的图像后,图像已经缩放,因为我希望当我滑动到其他图像时,图像应该恢复到其原始形式。
这是我下面的XMAl代码:-

<cards:CarouselView Grid.Row="1" PositionChanged="ImageCollection_PositionChanged" CurrentItemChanged="ImageCollection_CurrentItemChanged_1" IndicatorView="{x:Reference imageIndicator}" x:Name="ImageCollection">
                    <cards:CarouselView.ItemTemplate>
                        <DataTemplate>
                            <ContentView>
                                <Grid Padding="0" Margin="0">
                                    <pinch:PinchZoom>
                                        <pinch:PinchZoom.Content>
                                            <Image Source="{Binding image}" x:Name="ImageData" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill">
                                            </Image>
                                        </pinch:PinchZoom.Content>
                                    </pinch:PinchZoom>
                                </Grid>
                            </ContentView>
                        </DataTemplate>
                    </cards:CarouselView.ItemTemplate>
                </cards:CarouselView>
yv5phkfx

yv5phkfx1#

可以参考下面的代码,点击按钮后,图片显示原来的大小,可以在PositionChangedCurrentItemChanged中添加Button_Clicked的代码:
MainPage.xaml:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"             
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             
             x:Class="Forms_CarouseIView.MainPage"             
             xmlns:local="clr-namespace:Forms_CarouseIView;assembly=Forms_CarouseIView">    
    <ContentPage.Content>          
         <StackLayout Padding="20" 
                      x:Name="stacklayout">             
             <local:PinchToZoomContainer x:Name="PinchToZoomContainer">                 
                  <local:PinchToZoomContainer.Content >                     
                           <Image Source="ddd.png"/> 
                  </local:PinchToZoomContainer.Content>            
              </local:PinchToZoomContainer>            
              <Button Text="reset" Clicked="Button_Clicked"/>        
         </StackLayout>            
    </ContentPage.Content>
</ContentPage>

MainPage.xaml.cs:

namespace Forms_CarouseIView
{    
    public partial class MainPage : ContentPage    
    {        
      public static double scale1;        
      public static double tx;        
      public static double ty;  
      
      public MainPage()        
      {            
        InitializeComponent();        
      }  
      
      private void Button_Clicked(object sender, EventArgs e)        
      {            
        PinchToZoomContainer.Content.Scale=scale1;            
        PinchToZoomContainer.TranslationX=tx;            
        PinchToZoomContainer.TranslationY=ty;                   
      }    
    }
}

PinchToZoomContainer.cs:

namespace Forms_CarouseIView
{    
   public class PinchToZoomContainer : ContentView    
   {           
      ...      
      void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)        
      {            
         if (e.Status == GestureStatus.Started)            
         {                
            ...
               
            MainPage.scale1 = Content.Scale;                                
         }            
         if (e.Status == GestureStatus.Running)            
         {                
            ...            
         }            
         if (e.Status == GestureStatus.Completed)            
         {                
            ...
                 
            MainPage.tx = -xOffset;                
            MainPage.ty = -yOffset;            
         }        
      }    
    }
}

有关PinchToZoomContainer.cs的更多代码,您可以参考官方创建PinchToZoom容器。

相关问题