FlipView with zoom

纵然是瞬间 提交于 2019-12-11 07:15:11

问题


I have a problem with using FlipView with my pinch-zoom functionality implemented before using FlipView. Before I implemented FlipView I just loaded single Image and let user to change it using two buttons. It was not very user-friendly so I decided to use swiping functionality of FlipView. I managed to implement FlipView and it works Fine. Here is my sample of code:

    private void downloadImage(int position)
    {
        MyWebClient wc;
        wc = new MyWebClient(); //I just added int actualDownloadedImagePosition field to know loading of which image has finished
        wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);

        String url;
        wc.actualDownloadedImagePosition = position;
        url = URL+position+".jpg";

        wc.OpenReadAsync(new Uri(url), wc);

    }
    private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null && !e.Cancelled)
        {
            try
            {   

                BitmapImage image = new BitmapImage();
                image.SetSource(e.Result);
                Image im = new Image();
                im.Source=image;
                int pos = (((MyWebClient)sender).actualDownloadedImagePosition);
                flip.Items.Insert(pos-1, im); //Is this BTW right solution?
            }
            catch (Exception ex)
            {
            }
        }
    }

downloadImage() is executed at start for the first to images, the others are downloaded in future (when user swipe through them).

When I was not using FlipView I just could use this code in XAML (and of course suitable code in .cs file):

    <Image
        Name="foto"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Center"
        Margin="0,40,0,20"                  
        RenderTransformOrigin="0,0"
        Height="800"
        Stretch="Uniform"
        >
        <toolkit:GestureService.GestureListener>
            <toolkit:GestureListener
                PinchStarted="OnPinchStarted"
                PinchDelta="OnPinchDelta"
                DragDelta="OnDragDelta"
                DoubleTap="OnDoubleTap"/>
        </toolkit:GestureService.GestureListener>
        <Image.RenderTransform>
            <CompositeTransform
                ScaleX="1" ScaleY="1"
                TranslateX="0" TranslateY="0"/>
        </Image.RenderTransform>

    </Image>

But now I don't know how to make it right. I tried using ItemTemplate and some others solutions but I really have no idea how should it work. Can anyone help me? :)

来源:https://stackoverflow.com/questions/27630368/flipview-with-zoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!