0

I'm pretty new to this and also this isn't my code. I find it hard to figure anything out, but I'm doing my best. So the case is, that I have Grid element which contains FlipView and another Grid (it contains 4 SelectorButtons). Inside FlipView I have 3 WebViews and Frame. And now something I'm not able to figure out - when I interact with webview somehow (scroll for an instance) and tap any of buttons the app crashes. It throws System.ArgumentException: Value does not fall within the expected range. Touching Frame and then buttons works fine. Here's xaml code and buttons commands. 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>

Commands:

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;
    }

As I mentioned before, that code was written by someone else and I don't know why something is that way and something other way. Any suggestion would be much appreciated.

3
  • You need to get more information about the code generating the exception (method and line number). Not much we can do without it. Commented Apr 20, 2018 at 13:24
  • I got that much after second button is being selected: at Windows.UI.Xaml.Controls.Primitives.Selector.put_SelectedIndex(Int32 value) at [...].Pages.MainPage.<SetWebView2>d__12.MoveNext() Any suggestions how can I obtain more informations? Commented Apr 20, 2018 at 13:28
  • I forgot to mention about one thing - when I touch webview and then I long press button it will work fine after that. Commented Apr 23, 2018 at 8:21

1 Answer 1

0

I was able to manage app not to crash. Line which was causing problems was for example FlipView.SelectedIndex = 1; What I did was to put this statement into try-catch block. It doesn't crash anymore and, what is interesting, executes this line so app works like it's intended.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.