none
Collapsing a HubSection in a Hub with 5 sections causes app to crash RRS feed

  • Question

  • Hi there,

    I've come across a very weird bug(?): Trying to set a hub section's visibility as "Collapsed" causes the app to crash. Listening for an unhandled exception only gives me the vauge error of "Incorrect Parameter" with no stack trace.

    Code to replicate:

    XAML

        <Grid>
            <Hub Header="bad hub">
                <HubSection Header="Section 1" x:Name="section1">
                    
                </HubSection>
                
                <HubSection Header="Section 2" x:Name="section2">
                    
                </HubSection>
                
                <HubSection Header="Section 3" x:Name="section3">
                    <DataTemplate>
                        <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                            <Button x:Name="hideSection1Button" Click="hideSection1Button_Click" Content="Hide Section 1" />
                            <Button x:Name="hideSection2Button" Click="hideSection2Button_Click" Content="Hide Section 2" />
                            <Button x:Name="hideSection4Button" Click="hideSection4Button_Click" Content="Hide Section 4" />
                        </StackPanel>
                    </DataTemplate>
                </HubSection>
                
                <HubSection Header="Section 4" x:Name="section4">
                    
                </HubSection>
                
                <HubSection Header="Section 5" x:Name="section5">
                    
                </HubSection>
            </Hub>
        </Grid>

    Code-Behind:

            public MainPage()
            {
                this.InitializeComponent();
    
                this.NavigationCacheMode = NavigationCacheMode.Required;
            }
    
            /// <summary>
            /// Invoked when this page is about to be displayed in a Frame.
            /// </summary>
            /// <param name="e">Event data that describes how this page was reached.
            /// This parameter is typically used to configure the page.</param>
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                // TODO: Prepare page for display here.
    
                // TODO: If your application contains multiple pages, ensure that you are
                // handling the hardware Back button by registering for the
                // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
                // If you are using the NavigationHelper provided by some templates,
                // this event is handled for you.
            }
    
            private void hideSection1Button_Click(object sender, RoutedEventArgs e)
            {
                section1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
    
            private void hideSection2Button_Click(object sender, RoutedEventArgs e)
            {
                section2.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
    
            private void hideSection4Button_Click(object sender, RoutedEventArgs e)
            {
                section4.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

    Am I doing something wrong, or is this a bug in 8.1? Any help would be appreaciated as it's one of the last few things I'm trying to squash before putting out my app!

    Sunday, June 15, 2014 9:37 PM

Answers

  • It might be a bug. A different approach is to Remove/Add the HubSections.

    Give the Hub a name:    <Hub Header="bad hub" x:Name="hub">

    Hide a section with Remove():

            private void hideSection1Button_Click(object sender, RoutedEventArgs e)
            {
                hub.Sections.Remove(section1);
            }

    Use Add(), Insert(), or InsertAt() to restore a HubSection. If you want to keep the sections in a certain order, you'll need to check what sections are already in the Hub and insert it into the proper position.

    Monday, June 16, 2014 1:34 AM

All replies

  • It might be a bug. A different approach is to Remove/Add the HubSections.

    Give the Hub a name:    <Hub Header="bad hub" x:Name="hub">

    Hide a section with Remove():

            private void hideSection1Button_Click(object sender, RoutedEventArgs e)
            {
                hub.Sections.Remove(section1);
            }

    Use Add(), Insert(), or InsertAt() to restore a HubSection. If you want to keep the sections in a certain order, you'll need to check what sections are already in the Hub and insert it into the proper position.

    Monday, June 16, 2014 1:34 AM
  • I am having the exact same issue. I was converting the Hub control of a Silverlight App over to Winrt and this issue took me awhile to isolate to the Hub control. I am still trying to understand what the exact issue is but if I have Hubsections with some visible and others collapsed then the App throws an unhandledArgumentException. 

    Actually, the invalid parameter message is not the actual message. Something weird with the debugger because if I hover the mouse over the exception reference, it changes the message to System.ArgumentException: Value does not fall within the expected range.} !

    I gave the hub a name the sections have names. If I pull out the section 6 the exception does not occur. 

    • Edited by tnesham Sunday, June 28, 2015 12:03 AM
    Saturday, June 27, 2015 11:45 PM
  • I removed a piece of code in the xaml and the issue went away. There was a Visibility converter that looked like this:

    Visibility="{Binding Visibility, ElementName=AnotherSection, Converter={StaticResource myConverter}}

    After I removed ElementName the Hub control worked.

    But I consider this a bug....
    • Edited by tnesham Sunday, June 28, 2015 1:08 AM Not solved
    Sunday, June 28, 2015 12:20 AM