Results 1 to 6 of 6

Thread: vs2017 Wait for WPF to finish?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    vs2017 Wait for WPF to finish?

    I often run into problems with null exceptions in code because the WPF controls I refer to don't exist yet.

    Is there a way to idle code until WPF has finished rendering?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    Re: vs2017 Wait for WPF to finish?

    Can you be more specific? That a control hasn't been rendered doesn't mean that it doesn't exist.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: vs2017 Wait for WPF to finish?

    I try to set .isenabled and end up with a WPF page showing with a null reference exception. If the button existed it would simple enable or disable it

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    Re: vs2017 Wait for WPF to finish?

    Again, the fact that something is not rendered does not mean that it does not exist so your problem is almost certainly not that something is not rendered. If you're not prepared to provide a full and explanation of the problem then I'll waste no further time here.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: vs2017 Wait for WPF to finish?

    There isn't much to explain. I have this button
    Code:
    <Button x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="2" IsEnabled="False"/>
    Then in a combobox event I call this sub and I try to set it enabled or disabled

    Code:
        Private Sub EnableAdd()
            If loading = False Then
                If tbxName.Text <> "" And tbxServing.Text <> "" Then
                    btnAdd.IsEnabled = True
                Else
                    btnAdd.IsEnabled = False
                End If
            End If
        End Sub
    When I open the form it immediately says an object is not set to an instance of an object. If I comment out the isenabled lines it loads fine

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2012
    Posts
    136

    Re: vs2017 Wait for WPF to finish?

    Well I removed the call to that from a combobox textchanged event and it works fine. I guess loading the combobox triggers it too early. I don't really need the combobox event so I will just leave it this way.

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