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 9265677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:07:57+00:00 2026-06-18T14:07:57+00:00

I’ve found that in many cases the designer in Visual Studio 2010 or in

  • 0

I’ve found that in many cases the designer in Visual Studio 2010 or in Expression Blend 4 will crash if, for example, a WPF UserControl contains a control does something in code based on the control’s loaded event (like transition to a different Visual State via a call like VisualStateManager.GoToState(this, "AfterLoaded", true);).

My typical approach to solving these designer crashes is use the DesignerProperties.GetIsInDesignMode(this) approach in the control’s contructor:

public MyControl()
{
    // prevent designer crashes
    if (DesignerProperties.GetIsInDesignMode(this))
        return;

    Loaded += MyControlLoaded;
    Unloaded += MyControlUnloaded;
    IsVisibleChanged += MyControlIsVisibleChanged;    
}

This approach targets both Visual Studio 2010 and Expression Blend 4 and enables me to have my design surface visible again. However, it also removes any design-time preview that a designer might provide for me (like with the above-mentioned VSM state change on the loaded event). Blend, in particular, is able to provide that preview for me in its designer (if I switch to a different Blend tab and then switch back to the original tab I see the loaded animation run). Furthermore, with some controls that I have not yet applied the above approach to, Visual Studio 2010’s designer will crash, while Blend 4’s designer will not. Thus what I would like to do is check for only Visual Studio 2010’s designer so that I can let Blend’s designer pass through and provide its previewing abilities.

The benefit of this ability would be that I save time by not needing to build and run the application as often (to see things like the loaded animation) since Blend’s designer could give me its preview.

  • 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-18T14:07:58+00:00Added an answer on June 18, 2026 at 2:07 pm

    I’ve found something that works. The idea is use the DesignerProperties.GetIsInDesignMode(...) approach combined with checking for the process name that is running the code.

    For my VisualStudio 2010, I see that the process name is “devenv”:

    Visual Studio Process name

    Then I found this post which explains that the System.Diagnostics.Process is what we need to get at the process information. Knowing that, I created this helper method:

    private bool IsVisualStudio2010DesignerRunning()
    {
        using (var process = System.Diagnostics.Process.GetCurrentProcess())
        {
            const string visualStudio2010ProcessName = "devenv";
    
            if (process.ProcessName.ToLowerInvariant().Contains(visualStudio2010ProcessName)
                && DesignerProperties.GetIsInDesignMode(this))
            {
                return true;
            }
            else
                return false;
        }
    }
    

    To illustrate that this is working, here is an example of its application

    Its in a custom control that I wrote called SunkenBorder. This control has a behavior where it transitions to a certain VisualState at its first opportunity, so that this state is its initial state that the user sees. This code executes in the OnApplyTemplate() override. Expression Blend 4 is able to handle and display this at runtime. Visual Studio 2010’s designer on the other hand, crashes entirely, as it is unable to execute the Storyboard that is initiated by a call to VisualStateManager.GoToState(...).

    To better illustrate that this is working, I’m setting the background property of the control to blue in the OnApplyTemplate() code that targets the VS 2010 designer (see screenshots).

        /// Non-static constructor
        public SunkenBorder()
        {
            // Avoid Visual Studio 2010 designer errors
            if (IsVisualStudio2010DesignerRunning())
                return;
    
            // Expression Blend 4's designer displays previews of animations 
            //  that these event handlers initiate!
            Initialized += new EventHandler(SunkenBorder_Initialized);
            Loaded += new RoutedEventHandler(SunkenBorder_Loaded);
            Unloaded += new RoutedEventHandler(SunkenBorder_Unloaded);
    
            IsVisibleChanged += new DependencyPropertyChangedEventHandler(SunkenBorder_IsVisibleChanged);
        }
    
        // ...
    
        /// Used to set the initial VSM state (its the first opportunity).
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
    
    
            if (IsVisualStudio2010DesignerRunning())
            {
                // set a property just to illustrate that this targets only Visual Studio 2010:
                this.Background = Brushes.Blue;
                // return before doing VisualState change so Visual Studio's designer won't crash
                return;
            }
            // Blend 4 executes this at design-time just fine
            VisualStateManager.GoToState(this, "InitialState", false);
    
            // ...
        }
    

    Here’s how Expression Blend 4’s preview looks (notice the background of the SunkenBorder controls are not blue)…

    Blend 4 designer preview

    … and here’s what Visual Studio’s designer shows me. Now its designer is not crashed and the SunkenBorder controls’ backgrounds are all blue…

    Visual Studio 2010 designer preview

    … and finally, here’s the result at runtime (again the SunkenBorder controls’ backgrounds are not blue):

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.