locked
Error: "The parameter is incorrect."

    Question

  • I have an app in which I am navigating to another page using the Me.Frame.Navigate method. When I do this, I receive the following two errors:

    "The parameter is incorrect."

    "Value does not fall within the expected range."

    When I attempt to debug, I place a breakpoint at Me.Frame.Navigate in the first page, but it goes almost straight to the error after that. I have tried everything I could find in the debug settings to pinpoint the source of the error by stepping through the code, but it goes pretty much straight to the error in App.g.i.vb. What could be the problem, or what can I do to help figure it out? Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, February 04, 2015 11:55 PM

All replies

  • Hi Nathan,

    Please post some code or a repro project, otherwise I cannot understand your problem. The error message is not clear.

    Thank you for understanding.

    Regards, 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Thursday, February 05, 2015 9:51 AM
    Moderator
  • I just found out what is causing the problem, but I am still trying to figure out how to fix it. I have a control that inherits from ItemsControl, which has the following code:

    <ItemsControl
    	x:Class="GolfScoresUnivAppTest_Common.PlayerNames"
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:app="using:UniversalAppExtras" mc:Ignorable="d">
    	<ItemsControl.Resources>
    		<ResourceDictionary>
    			<ResourceDictionary.MergedDictionaries>
    				<ResourceDictionary Source="ms-appx:///UniversalAppExtras/NoDeleteTextBox.xaml"/>
    				<ResourceDictionary Source="ms-appx:///UniversalAppExtras/BasicButton.xaml"/>
    				<ResourceDictionary>
    					<app:IsNullOrWhiteSpaceConverter x:Key="IsNullOrWhiteSpace"/>
    					<app:HideValueOpacityConverter x:Key="HideValueOpacity"/>
    				</ResourceDictionary>
    			</ResourceDictionary.MergedDictionaries>
    		</ResourceDictionary>
    	</ItemsControl.Resources>
    	<ItemsControl.ItemsPanel><ItemsPanelTemplate><StackPanel/></ItemsPanelTemplate></ItemsControl.ItemsPanel>
    	<ItemsControl.ItemTemplate>
    		<DataTemplate>
    			<Grid x:Name="grdPlayerTemplate" Loaded="grdPlayerTemplate_Loaded">
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="*"/>
    					<ColumnDefinition Width="Auto"/>
    					<ColumnDefinition Width="Auto"/>
    				</Grid.ColumnDefinitions>
    				<TextBox Grid.Column="0" Style="{StaticResource NoDeleteTextBox}" FontSize="32" Margin="0,3" Padding="3,-6" Text="{Binding PlayerName}" Tag="{Binding Index}" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Stretch" IsTextPredictionEnabled="False" TextChanged="PlayerName_TextChanged" Loaded="PlayerName_Loaded" GotFocus="PlayerName_GotFocus"/>
    				<Button Grid.Column="1" Style="{StaticResource BasicButton}" FontSize="32" Margin="3,1.5" Padding="0,-2,1,-1" Content="&#xE10A;" Tag="{Binding Index}" FontFamily="Segoe UI Symbol" IsEnabled="{Binding Children[0].Text,ElementName=grdPlayerTemplate,Converter={StaticResource IsNullOrWhiteSpace},ConverterParameter=NOT}" Click="DeletePlayer_Click"/>
    				<Button Grid.Column="2" Style="{StaticResource BasicButton}" FontSize="32" Margin="0,1.5" Padding="8,1,8,2" Content="Move Up" Tag="{Binding Index}" IsEnabled="{Binding Children[0].Text,ElementName=grdPlayerTemplate,Converter={StaticResource IsNullOrWhiteSpace},ConverterParameter=NOT}" Opacity="{Binding Index,Converter={StaticResource HideValueOpacity}}" Click="MoveUp_Click"/>
    			</Grid>
    		</DataTemplate>
    	</ItemsControl.ItemTemplate>
    </ItemsControl>
    Public NotInheritable Class PlayerNames : Inherits ItemsControl : Implements INotifyPropertyChanged
    	Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
    	Public Event NamesChanged As EventHandler(Of NamesChangedEventArgs)
    	Public Event PlayerGotFocus(sender As Object, e As PlayerGotFocusEventArgs)
    	Private focusedindex As Integer = -1
    	Private cursorposition As Integer = 0
    	Private _playernames As New List(Of String)
    	Private _playerheight As Double = 0
    	Public Property PlayerNames() As List(Of String)
    		Get
    			Return Me._playernames
    		End Get
    		Set(value As List(Of String))
    			Me._playernames = value.Where(Function(n) Not String.IsNullOrWhiteSpace(n)).ToList()
    			Me.ItemsSource = Me.PlayerNames.Concat({""}).Select(Function(n, i) New With {.PlayerName = n, .Index = i})
    		End Set
    	End Property
    	Public ReadOnly Property PlayerCount() As Integer
    		Get
    			Return Me.PlayerNames.Count
    		End Get
    	End Property
    	Public ReadOnly Property PlayerHeight() As Double
    		Get
    			Return Me._playerheight
    		End Get
    	End Property
    
    	Private Sub PlayerNames_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    		Me.ItemsSource = Me.PlayerNames.Concat({""}).Select(Function(n, i) New With {.PlayerName = n, .Index = i})
    		RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PlayerCount"))
    	End Sub
    
    	Private Sub PlayerName_TextChanged(sender As Object, e As TextChangedEventArgs)
    		Dim index As Integer = CInt(CType(sender, TextBox).Tag)
    		Dim deleted As Boolean = False
    		Dim blankadded As Boolean = False
    		Dim initialplayercount As Integer = Me.PlayerCount
    		'Update Me.PlayerNames and rebind
    		If index = Me.PlayerNames.Count Then
    			'The last (blank) TextBox is having text entered for the first time
    			Me.PlayerNames.Add(CType(sender, TextBox).Text)
    			'Set focus on TextBox at index, this happens in PlayerNameTextBox_Loaded when rebinding
    			Me.focusedindex = index
    			Me.cursorposition = CType(sender, TextBox).SelectionStart
    			Me.ItemsSource = Me.PlayerNames.Concat({""}).Select(Function(n, i) New With {.PlayerName = n, .Index = i})
    			blankadded = True
    		Else
    			Me.PlayerNames(index) = CType(sender, TextBox).Text
    			If String.IsNullOrWhiteSpace(Me.PlayerNames(index)) Then
    				'If the current name is blank, remove it from Me.PlayerNames and rebind
    				Me.PlayerNames = Me.PlayerNames.Where(Function(n) Not String.IsNullOrWhiteSpace(n)).ToList()
    				'Set focus on TextBox at Me.PlayerNames.Count, this happens in PlayerNameTextBox_Loaded when rebinding
    				Me.focusedindex = Me.PlayerNames.Count
    				Me.cursorposition = 0
    				Me.ItemsSource = Me.PlayerNames.Concat({""}).Select(Function(n, i) New With {.PlayerName = n, .Index = i})
    				deleted = True
    			End If
    		End If
    		'Raise the NamesChanged event
    		RaiseEvent NamesChanged(Me, New NamesChangedEventArgs(Me.PlayerNames, index, deleted, blankadded))
    		'Raise the PropertyChanged event if the number of players is different
    		If Me.PlayerCount <> initialplayercount Then RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PlayerCount"))
    	End Sub
    
    	Private Sub PlayerName_GotFocus(sender As Object, e As RoutedEventArgs)
    		RaiseEvent PlayerGotFocus(Me, New PlayerGotFocusEventArgs(CInt(CType(sender, TextBox).Tag)))
    	End Sub
    
    	Private Sub DeletePlayer_Click(sender As Object, e As RoutedEventArgs)
    		Dim index As Integer = CInt(CType(sender, Button).Tag)
    		Me.PlayerNames.RemoveAt(index)
    		Me.ItemsSource = Me.PlayerNames.Concat({""}).Select(Function(n, i) New With {.PlayerName = n, .Index = i})
    		'Raise the NamesChanged event
    		RaiseEvent NamesChanged(Me, New NamesChangedEventArgs(Me.PlayerNames, index, True, False))
    		'Raise the PropertyChanged event
    		RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PlayerCount"))
    	End Sub
    
    	Private Sub MoveUp_Click(sender As Object, e As RoutedEventArgs)
    		Dim index As Integer = CInt(CType(sender, Button).Tag)
    		If index = 0 Then Exit Sub
    		Dim prevname As String = Me.PlayerNames(index - 1)
    		Me.PlayerNames(index - 1) = Me.PlayerNames(index)
    		Me.PlayerNames(index) = prevname
    		Me.ItemsSource = Me.PlayerNames.Concat({""}).Select(Function(n, i) New With {.PlayerName = n, .Index = i})
    		'Raise the NamesChanged event
    		RaiseEvent NamesChanged(Me, New NamesChangedEventArgs(Me.PlayerNames, index, False, False))
    	End Sub
    
    	Private Sub PlayerName_Loaded(sender As Object, e As RoutedEventArgs)
    		If CInt(CType(sender, TextBox).Tag) = Me.focusedindex Then
    			CType(sender, TextBox).Focus(FocusState.Programmatic)
    			CType(sender, TextBox).SelectionStart = Me.cursorposition
    		End If
    	End Sub
    
    	Private Sub grdPlayerTemplate_Loaded(sender As Object, e As RoutedEventArgs)
    		Me._playerheight = CType(sender, Grid).ActualHeight
    	End Sub
    End Class

    The problem has something to do with the NoDeleteTextBox & BasicButton resources. If I remove the Style property from the TextBox & Buttons in the DataTemplate, everything works fine (but they obviously don't have the look I want without the Style). In the "Resource Reference Debugging" section at the bottom of the following page:

    https://msdn.microsoft.com/en-us/library/gg181270(v=VS.95).aspx

    It says:

    "One common failure of resource lookup is making a forward reference: where the StaticResource reference to a key is made prior to the item definition of an item with that x:Key value." I am wondering if this could be the cause of my problem, but I am not quite sure how I would solve it. Could this be this problem, and if it is, how would I fix it? Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, February 05, 2015 5:04 PM