当我触摸 webview 内容然后在应用程序崩溃后在外面的某个地方

When I touch webview content and then somewhere outside after the app crashes

我对此很陌生,而且这不是我的代码。我发现很难弄清楚任何事情,但我正在尽力而为。所以情况是,我有 Grid 元素,其中包含 FlipView 和另一个 Grid(它包含 4 SelectorButtons)。在 FlipView 里面我有 3 个 WebViewsFrame。现在我无法弄清楚 - 当我以某种方式与 webview 交互(滚动实例)并点击应用程序崩溃的任何按钮时。它抛出 System.ArgumentException: Value does not fall within the expected range。触摸 Frame 然后按按钮就可以了。这是 xaml 代码和按钮命令。 Xaml:

        <FlipView.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </FlipView.ItemsPanel>



        <WebView x:Name="web1"
                 Source="{Binding Model.Widget1Url}"
                 Height="Auto"
                 Width="Auto"
                 HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch"
                 ScrollViewer.ZoomMode="Disabled"
                 ScrollViewer.VerticalScrollBarVisibility="Disabled"                    

                 Visibility="Visible" ManipulationMode="None" IsTapEnabled="False"/>

        <WebView x:Name="web2"
                 Source="{Binding Model.Widget2Url}"
                 Height="Auto"
                 Width="Auto"
                 HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch"
                 ScrollViewer.ZoomMode="Disabled"
                 ScrollViewer.VerticalScrollBarVisibility="Disabled"                    

                 Visibility="Visible" ManipulationMode="None"/>

        <WebView x:Name="web3"
                 Source="{Binding Model.Widget3Url}"
                 Height="Auto"
                 Width="Auto"
                 HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch"
                 ScrollViewer.ZoomMode="Disabled"
                 ScrollViewer.VerticalScrollBarVisibility="Disabled"                    
                 Visibility="Visible" ManipulationMode="None"/>

        <Frame Height="Auto"
               Width="Auto"
               HorizontalAlignment="Stretch"
                ManipulationMode="All" ManipulationCompleted="FlipView_ManipulationCompleted"  ManipulationStarted="FlipViewItem_ManipulationDelta"
               VerticalAlignment="Stretch"   
               Background="White"
               x:Name="contentFrame" DataContext="{Binding Model.UserLoginViewModel}"/>


    </FlipView>

    <Grid Grid.Row="1" VerticalAlignment="Bottom">
        <Grid.RowDefinitions>
            <RowDefinition Height="60"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <controls:SelectorButton x:Name="B1" Grid.Row="0" Grid.Column="0" Source="../images/tab_01.png" ActiveSource="../images/tab_active_01.png" ButtonCommand="{Binding Model.SetWebView1Command}"/>
        <controls:SelectorButton x:Name="B2" Grid.Row="0" Grid.Column="1" Source="../images/tab_02.png" ActiveSource="../images/tab_active_02.png" ButtonCommand="{Binding Model.SetWebView2Command}"/>
        <controls:SelectorButton x:Name="B3" Grid.Row="0" Grid.Column="2" Source="../images/tab_03.png" ActiveSource="../images/tab_active_03.png" ButtonCommand="{Binding Model.SetWebView3Command}"/>
        <controls:SelectorButton x:Name="B4" Grid.Row="0" Grid.Column="3" Source="../images/tab_04.png" ActiveSource="../images/tab_active_04.png" ButtonCommand="{Binding Model.LoginCommand}" />
    </Grid>
</Grid>

命令:

private async void SetWebView1()
    {
        if (FlipView.SelectedIndex == 3)
        {
            FlipView.SelectedIndex = 2;
            await Task.Delay(TimeSpan.FromSeconds(0.1));

            FlipView.SelectedIndex = 1;
            await Task.Delay(TimeSpan.FromSeconds(0.1));
        }

        if (FlipView.SelectedIndex == 2)
        {
            FlipView.SelectedIndex = 1;
            await Task.Delay(TimeSpan.FromSeconds(0.1));
        }

        FlipView.SelectedIndex = 0;
    }

    private async void SetWebView2()
    {
        if (FlipView.SelectedIndex == 3)
        {
            FlipView.SelectedIndex = 2;
            await Task.Delay(TimeSpan.FromSeconds(0.1));
        }
        FlipView.SelectedIndex = 1;

    }

    private async void SetWebView3()
    {
        if (FlipView.SelectedIndex == 0)
        {
            FlipView.SelectedIndex = 1;
            await Task.Delay(TimeSpan.FromSeconds(0.1));
        }
        FlipView.SelectedIndex = 2;
    }

    public async void SetLogin()
    {
        if (FlipView.SelectedIndex == 0)
        {
            FlipView.SelectedIndex = 1;
            await Task.Delay(TimeSpan.FromSeconds(0.1));

            FlipView.SelectedIndex = 2;
            await Task.Delay(TimeSpan.FromSeconds(0.1));
        }

        if (FlipView.SelectedIndex == 1)
        {
            FlipView.SelectedIndex = 2;
            await Task.Delay(TimeSpan.FromSeconds(0.1));
        }

        FlipView.SelectedIndex = 3;
    }

正如我之前提到的,该代码是由其他人编写的,我不知道为什么有些是这样,有些是其他的。任何建议将不胜感激。

我能够管理应用程序不崩溃。导致问题的行是例如 FlipView.SelectedIndex = 1; 我所做的是将此语句放入 try-catch 块中。它不再崩溃,有趣的是,它执行了这一行,所以应用程序按预期工作。