[英]Windows store app ScrollViewer.ChangeView() not working
嘗試在雙擊事件觸發的Windows應用商店應用中縮小滾動視圖。
這是它應該發生的代碼
private void MainPhotoDisplay_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
MainPhotoDisplayscrollViewer.ChangeView(null, null, 1.0F,true);
}
但如果我放大,在模擬器中,然后雙擊,沒有任何反應。 事件觸發並且方法運行但沒有任何反應,視圖仍然處於放大狀態。
這是它的文檔: http : //msdn.microsoft.com/en-us/library/windows/apps/dn252762.aspx
這個過時的方法:
MainPhotoDisplayscrollViewer.ZoomToFactor(1);
工作得很好,但遺憾的是它沒有動畫,這會導致糟糕的用戶體驗。 並不是我想要的。
關於為什么沒有發生的任何想法?
另一種解決方案是在指令之前添加Task.Delay
調用。
真的很奇怪,但它的確有效。
await Task.Delay(1);
scroller.ChangeView(null, null, null, false); // whatever
找到解決方案: http : //social.msdn.microsoft.com/Forums/windowsapps/en-US/c3eac347-fe08-41bd-98cb-d97b6f260873/double-tap-to-zoom-image-windows-81-scrollviewerchangeview?forum = winappswithcsharp
這里標記為解決方案的帖子實際上是有效的,但如果您使用有問題的scrollViewer在頁面的代碼隱藏中運行代碼,則不需要事件的前3行。 記得將調用中的最后一個bool設置為false以顯示動畫。
var period = TimeSpan.FromMilliseconds(10);
Windows.System.Threading.ThreadPoolTimer.CreateTimer(async (source) =>
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
var Succes = MainPhotoDisplayscrollViewer.ChangeView(null, null, 1.0F, false);
});
}, period);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.