none
HubSection content visual states

    Question

  • Hi,

    in my application I'm using the new Hub control introduced in Windows 8.1 Preview.
    In a HubSection I have a list of items and I would like to show different content basing on different states:

    - I show a progressring while loading the list of items .
    - I show a textblock with an error message if there's a loading error.
    - I show a textblock with a message if there's no error and no item in the list.
    - I show a listview if there's no error and at least one item in the list.

    I thougth to manage these different states using visual states and since I'm using Prism, I raise events from the viewmodel and in view codebehind I switch the visual states (waiting the final release for GoToStateAction behavior).

    The problem is that I get an exception switching visual state since I cannot access HubSection content template controls from the visual state storyboard.

    "An exception of type 'System.Exception' occurred in TestHubApp.exe but was not handled in user code
    Additional information: No installed components were detected. (Exception from HRESULT: 0x800F1000)"

    Then I defined visual states directly in HubSection and switch them in this way:

    VisualStateManager.GoToState(MySection, "TestState", true);

    I don't get any exception but the visual state doesn't switch.

    Previously I was using viewmodel properties to show or hide controls but with viewmodel events and view visual states is
    much more cleaner and easier to manage.

    Any idea?


    Sunday, July 28, 2013 10:33 AM

Answers

  • Hi,

    I found a solution using:

    • Using ExtendVisualStateManager (porting it from Silverlight).
    • Setting ExtendVisualStateManager as a CustomVisualStateManager in a Grid that I defined as a container in HubSection DataTemplate.
    • Switching visual states using ExtendedVisualStateManager:
      Grid mySectionContainer = MySection.FindChildByName("MySectionContainer") as Grid;
      ExtendedVisualStateManager.GoToElementState(mySectionContainer, "TestState", true);

    A little bit complex but it works very well.

    The only problem is that I don't have design time support in Blend for editing visual states.

    Will be ExtendedVisualStateManager available in the final release of Windows 8.1 and will we have design time support in Blend for visual states defined using ExtendedVisualStateManager?

    Sunday, July 28, 2013 11:25 AM

All replies

  • Hi,

    I found a solution using:

    • Using ExtendVisualStateManager (porting it from Silverlight).
    • Setting ExtendVisualStateManager as a CustomVisualStateManager in a Grid that I defined as a container in HubSection DataTemplate.
    • Switching visual states using ExtendedVisualStateManager:
      Grid mySectionContainer = MySection.FindChildByName("MySectionContainer") as Grid;
      ExtendedVisualStateManager.GoToElementState(mySectionContainer, "TestState", true);

    A little bit complex but it works very well.

    The only problem is that I don't have design time support in Blend for editing visual states.

    Will be ExtendedVisualStateManager available in the final release of Windows 8.1 and will we have design time support in Blend for visual states defined using ExtendedVisualStateManager?

    Sunday, July 28, 2013 11:25 AM
  • Hi,OasisLiveForever

    I'm glad to hear that you got it working.And your second question is more suited for a discussion type now.

    You could create a new discussion thread to go on this question,and i'll mark your answer as a answer.

    If you have any question with this, you could unmark it and post your question to me,i'm glad to service for you!

    Best regard

    Monday, August 05, 2013 1:33 AM
    Moderator