none
win8 app使用FlipView+ManipulationDelta做多点触控缩放图片,现FlipView.SelectionChanged无法触发?是不是二者不能结合使用? RRS feed

  • 问题

  • 本人在使用FlipView制作图片浏览,多点缩放时候遇到这一问题,当我图片浏览中没有添加ManipulationDelta可以正常进行滑动到下一张图片,但现在添加ManipulationDelta后,无法滑动到下一张图片。本人给FlipView注册了SelectionChanged事件,方便观察切换效果,跟踪代码发现,这个SelectionChanged事件事件再也没有触发过。这是什么原因啊?找了半天没发现哪里问题,求大神们指点下!

    以下是xmal代码                  

    <Grid Grid.Row="0" x:Name="imageGrid" Grid.RowSpan="3">
                <Grid.RenderTransform>
                    <Composi

    teTransform x:Name="FlipImageTranform"/>
                </Grid.RenderTransform>
                <FlipView x:Name="flipImage" Tapped="flipImage_Tapped" SelectionChanged="flipImage_SelectionChanged" ItemsSource="{Binding PictureFileList}" SelectedIndex="{Binding CurrentIndex,Mode=TwoWay}">        
                    <FlipView.ItemTemplate>
                        <DataTemplate>
                            <Image x:Name="FileViewImage" Stretch="Fill" ManipulationMode="All" ManipulationDelta="FileViewImage_ManipulationDelta" ManipulationCompleted="FileViewImage_ManipulationCompleted" Source="{Binding SamTumbImage}">
                            </Image>
                        </DataTemplate>
                    </FlipView.ItemTemplate>
                </FlipView>
            </Grid>

    下面是后台代码

     private void FileViewImage_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
            {
                FlipImageTranform.ScaleX *= e.Delta.Scale;
                FlipImageTranform.ScaleY *= e.Delta.Scale;
                FlipImageTranform.CenterX = e.Position.X;
                FlipImageTranform.CenterY = e.Position.Y;
                if (FlipImageTranform.ScaleX <= 1.0)
                {
                    FlipImageTranform.ScaleX = 1.0;
                    FlipImageTranform.ScaleY = 1.0;
                    //设置当前缩放比例为1,并可以进行切换到下一张图片
                    IsCanManipulate = true;  //为全局变量,提供判断是否可以进行滑动到下一张图片
                }
                else
                {
                    var newTranslateX = FlipImageTranform.TranslateX + e.Delta.Translation.X;
                    var newTranslateY = FlipImageTranform.TranslateY + e.Delta.Translation.Y;
                    if (newTranslateX < (-1 * (imageGrid.ActualWidth / 2)) || newTranslateX > (imageGrid.ActualWidth / 2))
                        return;
                    else
                        FlipImageTranform.TranslateX = newTranslateX;
                    if (newTranslateY < (-1 * (imageGrid.ActualHeight / 2)) || newTranslateY > (imageGrid.ActualHeight / 2))
                        return;
                    else
                        FlipImageTranform.TranslateY = newTranslateY;
                }
            }
     #region   设置下一个图片
            private void SetCurrentPictureIndex()
            {
                int index = GetIndex(pictureNameTbk.Text);
                if (index != _lAllPicture.Count - 1)
                {
                    index++;
                    flipImage.SelectedIndex = index; //设置当前index是成功,比如原来是9,现在设置是10,但changed事件没触发
                    flipImage.SelectedItem = _lAllPicture[index];   //lAllPicture为FlipView数据源
                }
            }
            #endregion 
            #region 触控完成
            private void FileViewImage_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
            {
                if (!IsCanManipulate) return;
                SetCurrentPictureIndex();
            }
            #endregion 
    private void flipImage_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
    //这个事件再也没有触发过
                FileInfo finfo = this.flipImage.SelectedValue as FileInfo;
                if (finfo !=null)
                    pictureNameTbk.Text = finfo.FileName;
            }
    FlipView绑定的SelectedIndex="{Binding CurrentIndex,Mode=TwoWay}">对应的CurrentIndex也做了通知
     private int currentIndex;
            public int CurrentIndex
            {
                get
                {
                    return currentIndex;
                }
                set
                {
                    if (value != currentIndex)
                    {
                        currentIndex = value;
                        NotifyChanged("CurrentIndex");

    求高手帮忙!小弟实在是找不出问题出在哪了,纠结啊!
    2013年9月6日 6:13

答案

  • Hi Billy,

    回复的比较晚见谅,我个人认为是因为你的Image已经侦听了Manipulation的事件,所以所有触发的事件都会被Image所handle,也就是说传递不到FlipView控件中,可能你需要一个Route Event的办法来解决,参考http://msdn.microsoft.com/en-us/library/windows/apps/hh758286.aspx

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月9日 11:05
    版主

全部回复

  • anyone can teach me ?
    2013年9月6日 8:46
  • Hi Billy,

    回复的比较晚见谅,我个人认为是因为你的Image已经侦听了Manipulation的事件,所以所有触发的事件都会被Image所handle,也就是说传递不到FlipView控件中,可能你需要一个Route Event的办法来解决,参考http://msdn.microsoft.com/en-us/library/windows/apps/hh758286.aspx

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月9日 11:05
    版主
  • thank you ! James!   按照Route Event的思想,我的是不需要在image的Manipulation达到一定条件,或者在ManipulationCompleted事件中,注册另外一个事件B,通过B事件去诱导FlipView的SelectionChanged触发。不知道我这样的理解对不对!
    2013年9月11日 10:14
  • Hi Billy,

    我建议你通过条件判断来触发FlipView的SelectionChanged事件。我们这么来说吧,FlipView翻页的事件的手势是向左或者向右滑动短距离,在Image上做这个动作会被认为你在移动图片,你可以加上一个判断,比如说手指移动距离小于50px就触发SelectionChanged的事件。

    Best Regards

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月12日 9:33
    版主