Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF Design-Time Headaches

WPF Design-Time Headaches

Scheduled Pinned Locked Moved WPF
csharpquestiondatabasewpfwinforms
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GenJerDan
    wrote on last edited by
    #1

    Everything is wonderful. Then all of a sudden, it starts throwing exceptions...in the Designer. The app itself compiles fine, runs fine, I just can't see any of the user controls because of index out of range and the like. Duh. How can I have an SelectionChanged event coded if it keeps objecting to me using the SelectedIndex property in it? Yeah, yeah, I know. But why has it worked fine for months and now it doesn't? Some magic setting somewhere I accidentally set or unset? VS2012, C#

    YouTube and My Mu[sic], Films and Windows Programs, etc.

    J 1 Reply Last reply
    0
    • G GenJerDan

      Everything is wonderful. Then all of a sudden, it starts throwing exceptions...in the Designer. The app itself compiles fine, runs fine, I just can't see any of the user controls because of index out of range and the like. Duh. How can I have an SelectionChanged event coded if it keeps objecting to me using the SelectedIndex property in it? Yeah, yeah, I know. But why has it worked fine for months and now it doesn't? Some magic setting somewhere I accidentally set or unset? VS2012, C#

      YouTube and My Mu[sic], Films and Windows Programs, etc.

      J Offline
      J Offline
      Jason Gleim
      wrote on last edited by
      #2

      I usually find this is an issue for two reasons: - A (dependency) property on a control is not being set in the default or specified style. This usually happens most on custom controls or controls where I have overridden the default template. Specifying a default value for a property in the default style will usually make this one go away. - A custom control (or extended control) doesn't handle the binding to a null object correctly. If, for example, you have something bound to a property on a view model but that property is a nullable type, in design mode it will probably be null. When the design surface mocks the VM to present a design-time view, the property evals to null and can throw an exception if the control doesn't handle it properly. If it is a control you wrote/overrode, you can fix it by handling a null value bound to the offending DP. Otherwise, add design-time code to provide a valid value for the offending VM property. (If you are using a framework like MVVMLight, IsInDesignMode is part of the VM base class. Otherwise, System.ComponentModel.DesignerProperties.GetIsInDesignMode will tell you. Beyond this, good luck. Xaml designer exceptions are especially painful to try to decode. It won't make you feel any better but I've even had the design surface crash repeatedly but clear up after a reboot.

      G 1 Reply Last reply
      0
      • J Jason Gleim

        I usually find this is an issue for two reasons: - A (dependency) property on a control is not being set in the default or specified style. This usually happens most on custom controls or controls where I have overridden the default template. Specifying a default value for a property in the default style will usually make this one go away. - A custom control (or extended control) doesn't handle the binding to a null object correctly. If, for example, you have something bound to a property on a view model but that property is a nullable type, in design mode it will probably be null. When the design surface mocks the VM to present a design-time view, the property evals to null and can throw an exception if the control doesn't handle it properly. If it is a control you wrote/overrode, you can fix it by handling a null value bound to the offending DP. Otherwise, add design-time code to provide a valid value for the offending VM property. (If you are using a framework like MVVMLight, IsInDesignMode is part of the VM base class. Otherwise, System.ComponentModel.DesignerProperties.GetIsInDesignMode will tell you. Beyond this, good luck. Xaml designer exceptions are especially painful to try to decode. It won't make you feel any better but I've even had the design surface crash repeatedly but clear up after a reboot.

        G Offline
        G Offline
        GenJerDan
        wrote on last edited by
        #3

        Yeah. If I do a Clean and then a Rebuild, it displays nicely...for a few minutes, then goes back to not being able to display the controls. It's just annoying. Of course, any changes I make to the user controls are done on themselves, not on their parent, so it's not a problem as such. Just grrrr. :p I just can't figure what I could possibly have done to make it stop working after it has been working for so long.

        YouTube and My Mu[sic], Films and Windows Programs, etc.

        S 1 Reply Last reply
        0
        • G GenJerDan

          Yeah. If I do a Clean and then a Rebuild, it displays nicely...for a few minutes, then goes back to not being able to display the controls. It's just annoying. Of course, any changes I make to the user controls are done on themselves, not on their parent, so it's not a problem as such. Just grrrr. :p I just can't figure what I could possibly have done to make it stop working after it has been working for so long.

          YouTube and My Mu[sic], Films and Windows Programs, etc.

          S Offline
          S Offline
          SledgeHammer01
          wrote on last edited by
          #4

          It usually gives you a pretty damn good hint as to what's wrong. Either in the error dialog or red / blue squiggles. It's entirely possible to have your XAML squiggled without seeing the error dialog. Some people like to ignore those squiggles, but 11 times out of 10, they indicate a real problem. If you aren't getting an error dialog or squiggles, you can add a global exception handler to your app and pop up a message box, do a full re-build and restart Visual Studio. When it loads your XAML and gets the exception, it'll pop up the message box. You are probably accessing something that isn't available / initialized yet at design time.

          G 1 Reply Last reply
          0
          • S SledgeHammer01

            It usually gives you a pretty damn good hint as to what's wrong. Either in the error dialog or red / blue squiggles. It's entirely possible to have your XAML squiggled without seeing the error dialog. Some people like to ignore those squiggles, but 11 times out of 10, they indicate a real problem. If you aren't getting an error dialog or squiggles, you can add a global exception handler to your app and pop up a message box, do a full re-build and restart Visual Studio. When it loads your XAML and gets the exception, it'll pop up the message box. You are probably accessing something that isn't available / initialized yet at design time.

            G Offline
            G Offline
            GenJerDan
            wrote on last edited by
            #5

            Yep. No squiggles, though. And the Stack Traces and Inner Exceptions pointed to all sorts of bizarre places having nothing to do with the actual problem:

            App.Current.Windows[0]

            App is apparently not available at designtime. So I wrapped the place it was being used in

            YouTube
            and
            My Mu[sic], Films and Windows Programs, etc.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups