Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:48:20+00:00 2026-06-02T08:48:20+00:00

I often find the need to include away and present type visual states that

  • 0

I often find the need to include “away” and “present” type visual states that are used to animate the control being away or visible depending on some other condition.

The “away” state is then usually the one that should be the initial state. To my understanding, there is no way to define an initial state in SL but “base”, which isn’t really a state at all but denotes how the look is with the state manager being not yet active (no state storyboards are running to change the look of the control).

Of course you can design “base” to look like “away”, but that means the default look in Expression Blend is invisible (you can’t “pin” a state permanently either).

To change the initial state I tried

  • setting the state in the ctor of the control, which does nothing and
  • setting the state in a dispatched call from the ctor or the Loaded event, which both show the wrong state for a split-second.

So the problem appears to be that whatever the visual state manager does, it doesn’t do it right away but needs a noticeable split-second to change the appearance.

(Setting the property directly for bootstrap is another option of course, but only works for UserControls: In templated Controls, I would have to introduce another depprop to template-bind the control template against, which is where I believe overkill starts.)

I suppose I covered it all and I just have to live with an invisible base state?

I use SL4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:48:23+00:00Added an answer on June 2, 2026 at 8:48 am

    I encountered a similar issue when developing a UserControl for WPF in Expression Blend (Note: if you’re developing a custom control instead, see my next section). In that UserControl, I had a child element that I wanted to fade in and grow into existence as an overlay. Like your situation, it made sense in my workflow to first design the overlay element at its “fully grown and visible” state and then shrink it down and set its opacity for a “Hidden” state. In doing this, the overlay is visible in the Base state, but I needed the UserControl’s initial state to be the Hidden state. At this point I had three main relevant states: Base, “Hidden” and “Visible” (these last two are a part of a State group).

    Here’s how I solved the initial-state issue. First I applied a GoToStateAction to the root element (to the UserControl) that is triggered by the Loaded event. It tells the UserControl to go right to the “Hidden” state:

    enter image description here

    <i:Interaction.Triggers>
      <i:EventTrigger>
        <ei:GoToStateAction TargetObject="{Binding ElementName=userControl}" StateName="Hidden"/>
      </i:EventTrigger>
    </i:Interaction.Triggers>
    

    Second, I made appropriate transition settings in the State Group for the overlay. There are probably several ways of doing this, but here’s how I did it. First I set the “Default transition” to a pleasing setting, say .4 seconds. Next, I set the transition time from any element (the star icon in Blend) to this “Hidden” state to be 0 seconds (this allows the above-mentioned GoToStateAction to set the “initial” state without the user knowing any different). Then, I set the transition from the “Visible” state to the “Hidden” state to be an appropriate setting (say .4 seconds). Basically this covered all the bases for the transitions. The key was making sure that the “transition” from “any element” to the “Hidden” state was immediate, and then overriding that immediate transition in the case of going from the overlay’s “Visible” to “Hidden” states.

    enter image description here


    Setting an Initial VisualState of a Custom Control

    If you’re developing a custom control (rather than a UserControl) and are thus defining your VisualStateManager in the control template, the above method (initiating the VisualState change based on the Loaded event) will probably not work. This is because the visual tree of your control (defined in a Style file) gets applied to your control right before the OnApplyTemplate() override gets called, which is usually after the first Loaded event has fired. So if you try to initiate a VisualState change in response to the Loaded event for a custom control, most likely nothing will happen. Instead, you will need to initiate the state change in your OnApplyTemplate() override code:

    public class MyCustomControl : ContentControl
    {
        // ... other code ....
    
    
        public MyCustomControl()
        {
            // avoid designer errors
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
    
            Loaded += new RoutedEventHandlerMyCustomControl_Loaded);
        }
    
        // This probably won't be called until AFTER OnApplyTemplate() gets
        //  called, so don't expect for your control to even have a visual tree
        //  yet when your control is first being contructed at runtime.
        private void MyCustomControl_Loaded(object sender, RoutedEventArgs e)
        {
    
        }
    
        public override void OnApplyTemplate()
        {
            // Avoid Visual Studio 2010 designer exceptions
            // (Visual Studio can't handle the VisualState change at design-time)
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
    
            base.OnApplyTemplate();
    
            // Now we know that the template has been applied, we have a visual tree,
            //  so state changes will work
            VisualStateManager.GoToState(this, "MyInitialState", false);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When programming for the iPhone, I find that I often need to use the
I often find myself needing reference to an object that is several objects away,
I often find myself in need of writing down a future Visual Studio solution
Thank you for your reading. I often find that I need to apply a
Often i have a problem that I need to determine which assebmly to include
Often I find myself filling ASP.NET repeaters with items that need the CSS class
Here at work, we often need to find a string from the list of
I often find linq being problematic when working with custom collection object. They are
I often find myself confused with how the terms 'arguments' and 'parameters' are used.
I often find myself writing a property that is evaluated lazily. Something like: if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.