Reputation: 71
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.
Upvotes: 0
Views: 122
Reputation: 71
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.
Upvotes: 0