火焰控制——在WP7中手动启动

10

我在WP7中有一个WebScrollView,它最初没有焦点(内容是hittestVisible,因此会使滚动视图的hittestvisibility失效)。当我将其内容的可见性设置为false时,我可以滚动滚动视图,但只能在抬起手指并再次放回后才行。我真的希望焦点能够转移,并在此之后重新应用焦点,以便在滚动视图获得焦点后滑动,而不是等待下一个manipulationStarted事件触发。

<UserControl 
x:Class="WTFApp.Resources.ViewControllers.DetailedItemContentControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EiBaseApi.Animation;assembly=EiBaseApi"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True" >

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="10"/>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.Resources>
        <Storyboard x:Name="MediatedListBoxContentAnimator">
            <DoubleAnimation x:Name="MediatedAnimation"
                             Storyboard.TargetName="WebScrollViewMediator"
                             Storyboard.TargetProperty="ScrollableWidthMultiplier" >
            </DoubleAnimation>
        </Storyboard>

    </Grid.Resources>

    <ScrollViewer x:Name="Scroller"
                  HorizontalScrollBarVisibility="Auto" 
                  VerticalScrollBarVisibility="Disabled"
                  ManipulationMode="Control"
                  Grid.Row="1" 
                  Grid.RowSpan="2" >
        <StackPanel Name="WebScrollView" Orientation="Horizontal">
            <UserControl Name="LeftContentControl"   MinWidth="480" />
            <UserControl Name="MiddleContentControl" MinWidth="480" />
            <UserControl Name="RightContentControl"  MinWidth="480" />
        </StackPanel>
    </ScrollViewer>
    <local:ScrollableItemAnimationMediator x:Name="WebScrollViewMediator" 
                                           ScrollViewer="{Binding ElementName=Scroller}"/>        
</Grid>

在C#中:

protected override void TouchFrameDelta( object sender, TouchFrameEventArgs e )
    {
        if ( UserManipulating == ManipulationState.ManipulationStopped )
        {
            UserManipulating = ManipulationState.ManipulationStarted;
            ManipulationStartingPoint = e.GetPrimaryTouchPoint( null ).Position;
        }
        //if we are already manipulating the scrollviewer, we do nothing
        if ( UserManipulating != ManipulationState.ManipulationStarted )
        {
            return;
        }
        TouchPoint touchPoint = e.GetPrimaryTouchPoint( null );
        float differenceStart = ( float )( touchPoint.Position.X - ManipulationStartingPoint.X );
        if ( Math.Abs( differenceStart ) >= 25 )
        {
            if ( BrowserListIsHitTestVisible )
            {
                BrowserListIsHitTestVisible = false;
                MiddleContentControl.Focus( );
                MiddleContentControl.UpdateLayout( );
                return;
            }

            float differenceDelta = ( float ) ( touchPoint.Position.X - ManipulationDeltaPoint.X );
            if ( touchPoint.Action == TouchAction.Up )
            {                    
                UserManipulating = ManipulationState.ManipilatingScrollViewCompleted;
                OnManipulationCompleted( differenceDelta );
            }                          
        }
        ManipulationDeltaPoint = touchPoint.Position;      
    }

TouchFrameDelta是一个Touch.FrameReported事件。 有人知道为什么这不起作用,以及如何修复吗? 提前致谢。


澄清一下,最终目标是拥有一个水平滚动的面板,其中内容为三个水平堆叠的用户控件?如果是的话,使用默认的ScrollViewer行为不适用于此(将ScrollViewer的IsHitTestVisible属性设置为true)? - codechinchilla
问题在于,当我设置IsHitTestVisible或任何其他用户输入布局更改时,都会在用户释放并重新放置手指后处理。我猜这与操作开始事件有关。当浏览器声明hittestvisibility时,scrollviewer的manipulationstartedevent不会被触发,只有在下一个manipulationstarted事件中才会捕获和处理它。因此,即使我水平滚动,更新布局,做各种奇怪的更新操作,浏览器仍然是hittestvisible,并且保持这种状态,直到我释放并重新应用输入。 - GeekPeek
能否提供您在页面中使用的实际XAML代码?这样我们可以更准确地尝试复现问题。 - codechinchilla
1个回答

1

为了澄清一下,ManipulationStarted(和Completed)不能手动触发,因为它们的EventArgs是没有任何公共构造函数的。

你所要求的,并不是我认为可能的事情。由于你的子项最初不支持任何交互,即使在你执行另一个事件之前设置了IsHitTestVisible,事件也不会向下传递到它。

我看不出你到底想要实现什么,但是在7.0/7.5中搞乱滚动和WebBrowser并不是我推荐的做法,因为这些控件的功能非常有限。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接