jeudi 21 mars 2019

C# WPF Checkbox with null value?

I am currently making a GUI in WPF, and am working on a page intended to create and configure message rooms but the following code below

else if (Password_Enabled.IsChecked == true && Password.Text.Length == 0)
        {
            return false; 
        }

appears with an error of

Password_Enabled.IsChecked 'Password_Enabled.IsChecked' threw an exception of type 'System.NullReferenceException'

My Xaml for the CheckBox appears as follows

<CheckBox x:Name="Password_Enabled" IsChecked="False" Content="Password Enabled" HorizontalAlignment="Left" VerticalAlignment="Top" Checked="Password_Enabled_Checked" Unchecked="Password_Disabled_Checked" Margin="10,5,0,0" Grid.RowSpan="2"/>

I've searched online, but with errors like these it's standardised, I know it means that the checkbox is being treated as null. But while searching through my code haven't found anything stating why, any help on this would be much appreciated, thank you.




Aucun commentaire:

Enregistrer un commentaire