积极答复者
FlipView 缩放图片

问题
答案
-
你的想法是对的,做法是错的。具体如下
int lastID = 0; private void fv_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (lastID != fv.SelectedIndex) { var dpobj = fv.ItemContainerGenerator.ContainerFromIndex(lastID); // 找到上一个子项的容器 ScrollViewer sv = FindVisualChild<ScrollViewer>(dpobj); // 从容其中找到该子项的ScrollViewer if (sv != null) { sv.ZoomToFactor(1.0f); // 重置ScrollViewer } else { Debug.WriteLine("null"); } lastID = fv.SelectedIndex; } } catch (Exception ex) { } } public static T FindVisualChild<T>(DependencyObject parent) where T : DependencyObject { T t = default(T); int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { DependencyObject child = VisualTreeHelper.GetChild(parent, i); t = (child as T); if (t == null) { t = FindVisualChild<T>(child); } if (t != null) { break; } } return t; }
别紧张,我不是什么好人。。。
- 已标记为答案 刀刀入梦 2013年4月8日 1:47
全部回复
-
Hi,
你具体的缩放是怎么实现的呢?
Aaron
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
你的想法是对的,做法是错的。具体如下
int lastID = 0; private void fv_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (lastID != fv.SelectedIndex) { var dpobj = fv.ItemContainerGenerator.ContainerFromIndex(lastID); // 找到上一个子项的容器 ScrollViewer sv = FindVisualChild<ScrollViewer>(dpobj); // 从容其中找到该子项的ScrollViewer if (sv != null) { sv.ZoomToFactor(1.0f); // 重置ScrollViewer } else { Debug.WriteLine("null"); } lastID = fv.SelectedIndex; } } catch (Exception ex) { } } public static T FindVisualChild<T>(DependencyObject parent) where T : DependencyObject { T t = default(T); int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { DependencyObject child = VisualTreeHelper.GetChild(parent, i); t = (child as T); if (t == null) { t = FindVisualChild<T>(child); } if (t != null) { break; } } return t; }
别紧张,我不是什么好人。。。
- 已标记为答案 刀刀入梦 2013年4月8日 1:47