UWP:如果缩放系数大于1,则SCrollViewer.ChangeView不滚动

时间:2019-01-04 20:54:05

标签: uwp scrollviewer zooming panning

我在Windows 10的UWP应用中添加了ScrollViewer。

我想同时使用它进行缩放和平移。

这是我的XAML:

### Time difference
reset session

$Data <<EOD
2019-01-04-11:01:31,1.593
2019-01-04-11:01:33,1.592
2019-01-04-11:01:36,1.593
2019-01-04-11:01:38,1.593
2019-01-05-00:05:00,1.590
2019-01-06-00:06:00,1.591
2019-01-07-00:07:00,1.592
EOD

set datafile separator ","
set xdata time
MyTimeFormat = "%Y-%m-%d-%H:%M:%S"
set timefmt MyTimeFormat
set format x "%tH:%tM"

set multiplot layout 2,1

# Solution 1: StartTime hardcoded
StartTime = strptime(MyTimeFormat,"2019-01-04-11:01:31")
plot $Data u ((timecolumn(1)-StartTime)):2 w lp pt 7  lc rgb "red"

# Solution 2: Take first line automatically as StartTime
set table $Dummy
    plot $Data u 0:(AutoStartTime = timecolumn(1,MyTimeFormat)) every ::0::0 with table
unset table
plot $Data u ((timecolumn(1)-AutoStartTime)):2 w lp pt 7 lc rgb "blue"

unset multiplot
### end of code

对于平移,我为PointerMoved事件添加了一个小型事件处理程序,如下所示:

<Page
    x:Class="LiquidTextUWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lt="using:LiquidTextUWP.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
  <ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" 
                ZoomMode="Enabled" Background="DarkSeaGreen" Name="ScrollArea" 
                Width="10000" Height="10000">
    <Grid Background="LightGray" Name="Workspace">
      <!-- here I put all my other controls -->
    </Grid>
  </ScrollViewer>
</Page>

private double previousX = 0; public void OnPointerMoved(object sender, PointerRoutedEventArgs e) { if (!(sender is ScrollViewer scrollViewer)) return; PointerPoint pp = e.GetCurrentPoint(null); double deltaX = pp.Position.X - previousX; previousDeltaX = pp.Position.X bool res = scrollViewer.ChangeView(scrollViewer.HorizontalOffset - deltaX, null, null); e.Handled = true; } 时,它工作得很好(也就是说,它实际上是水平平移,res = true)。

取而代之的是scrollViewer.ZoomFactor > 1,它什么也不做(和scrollViewer.ZoomFactor < 1)。

编辑: 我还注意到,当res = false时,属性scrollViewer.ZoomFactor < 1ScrollableWidth变为0,而当ScrollableHeight时,属性scrollViewer.ZoomFactor > 1ScrollableWidth为肯定的。

当缩放系数小于1时,如何使ScrollViewer也为ChangeView返回true?

2 个答案:

答案 0 :(得分:0)

我认为您必须将ScrollViewer.ZoomMode设置为Enabled

最诚挚的问候

答案 1 :(得分:0)

为了将来会碰到这个话题的人们,这是我解决的方法:

我必须将ScrollArea的宽度/高度设置为小于Workspace元素的宽度/高度。

我的问题是将ScrollArea的宽度/高度设置为10000。如果我将其设置为“自动”(或不显示它),而是将Workspace的宽度/高度设置为10000,那么我就有想要的效果。