سؤال

Iam using a Progress bar to show the progress of loading features, ini WPF. The xaml code looks like this,

  <Grid>
   <ProgressBar Height="13" HorizontalAlignment="Left" Margin="47,117,0,0" Name="progressBar1" VerticalAlignment="Top" Width="291" Value="0" IsIndeterminate="True" />
  <Grid>

and in code behind,

   public SplashScreen()
    {   
        InitializeComponent();         

        Duration duration = new Duration(TimeSpan.FromSeconds(10));
        DoubleAnimation doubleanimation = new DoubleAnimation(30.0, duration);

        progressBar1.BeginAnimation(ProgressBar.ValueProperty,doubleanimation); //Exception

    }       

While executing the code, it throws me an exception in the last line stating that "Object reference not set to an instance of an object.".

Can anyone help me to overcome this exception and to make my progressbar work.

هل كانت مفيدة؟

المحلول

If you get that Exception on the last line, then the only object on that line that could be null is your progressBar1 object. Only you can tell why it is null.

نصائح أخرى

I found out why the exception occurs. Since iam using the code in Constructor, am encountering the exception. When Iam using the same in load_event(), no problem....

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top