Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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....

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top