Results 1 to 3 of 3

Thread: wpf comboboxes causeing null reference crash when visibility or width used in code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    93

    wpf comboboxes causeing null reference crash when visibility or width used in code

    I filled a combobox in codebehind and it works correctly. I also set its visibilty to visibility.collapsed in the same function without problem.

    when I try to set it to visibility.collapsed later (checkbox checked event) I crash saying something is null. Same thing if I try to set isenabled or anything else. I would think it was a scope problem but it is declared in wpf so it should be available to all code in the codebehind right? If that was the problem then I shouldn't have been able to populated the list from codebehind either as far as I know.

    Any thoughts?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    108,349

    Re: wpf comboboxes causeing null reference crash when visibility or width used in cod

    Quote Originally Posted by pmeloy View Post
    I crash saying something is null.
    The first thing to do is work out what is null. That's what you have a debugger for. Once you know what is null, then you can work backwards to work out why.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    93

    Re: wpf comboboxes causeing null reference crash when visibility or width used in cod

    No idea what is null. The exception shows up at the title of the wpf page
    Code:
    <Window x:Class="AdminProfitLoss"
    BUT, you twigged a thought so I added a "loading" variable that is true at startup and false after the loading is complete and ignored any settings while it is true. Now it works fine!
    I guess it was a case of the combobox not being created before the form_load was being run. I had thought the WPF code was loaded first but I guess not

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width