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

问题
-
本人在使用FlipView制作图片浏览,多点缩放时候遇到这一问题,当我图片浏览中没有添加ManipulationDelta可以正常进行滑动到下一张图片,但现在添加ManipulationDelta后,无法滑动到下一张图片。本人给FlipView注册了SelectionChanged事件,方便观察切换效果,跟踪代码发现,这个SelectionChanged事件事件再也没有触发过。这是什么原因啊?找了半天没发现哪里问题,求大神们指点下!
以下是xmal代码
<Grid Grid.Row="0" x:Name="imageGrid" Grid.RowSpan="3">
<Grid.RenderTransform>
<CompositeTransform 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");
求高手帮忙!小弟实在是找不出问题出在哪了,纠结啊!
答案
-
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.- 已标记为答案 Jamles HezModerator 2013年9月18日 6:48
全部回复
-
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.- 已标记为答案 Jamles HezModerator 2013年9月18日 6:48
-
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.