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?
Printable View
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?
Can you be more specific? That a control hasn't been rendered doesn't mean that it doesn't exist.
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
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.
There isn't much to explain. I have this buttonThen in a combobox event I call this sub and I try to set it enabled or disabledCode:<Button x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="2" IsEnabled="False"/>
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 fineCode: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
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.