0

(System.ArgumentException) Value does not fall within the expected range exception thrown while open the popup in another one popup in uwp.

Popup open from the button click. Please refer the code

<Button Width="50" Height="30" Name="btn1" 
            HorizontalAlignment="Center" VerticalAlignment="Center" 
            Content="Click" Click="Button_Click" />
    <Popup Name="popUp1" Width="200" Height="200"/>
    <Popup Name="popUp2" Width="200" Height="200"/>

private void Button_Click(object sender, RoutedEventArgs e)
    {
        Button btn2 = new Button();
        btn2.Width = 200;
        btn2.Height = 50;            
        btn2.Content = "PopUp1";
        popUp1.Child = btn2;
        popUp1.IsOpen = true;
        btn2.Click += Btn2_Click;
    }

    private void Btn2_Click(object sender, RoutedEventArgs e)
    {            
        popUp2.Child = btn1;
        popUp2.IsOpen = true;
    }

enter image description here

1 Answer 1

1

(System.ArgumentException) Value does not fall within the expected range exception thrown

This exception is because you tried to set the btn1 as the Child of popUp2, but the btn1 already has the parent panel. So if you still want the btn1 to be the child of popUp2, you can first remove it from its parent panel or you can create a new Button and set its Click event as the btn1's Click event. For example:

.xaml:

<StackPanel x:Name="MyPanel">
    <Button Width="50" Height="30" Name="btn1" 
        HorizontalAlignment="Center" VerticalAlignment="Center" 
        Content="Click" Click="Button_Click" />
    <Popup Name="popUp1" Width="200" Height="200"/>
    <Popup Name="popUp2" Width="200" Height="200"/>
</StackPanel>

.cs:

private void Btn2_Click(object sender, RoutedEventArgs e)
{
    MyPanel.Children.Remove(btn1);
    popUp2.Child = btn1;
    popUp2.IsOpen = true;
}

Or

private void Btn2_Click(object sender, RoutedEventArgs e)
{
    Button btn = new Button();
    btn.Width = 200;
    btn.Height = 50;
    btn.Content = "PopUp2";
    btn.Click += Button_Click;
    popUp2.Child = btn;
    popUp2.IsOpen = true;
}
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.