PictureBox and ProgressBar controls in WPF
Image:
Namespace : System.Windows.Controls.Image
Designer Code:
<StackPanel>
<Image Name="img1" Source="Images\win2wpf.JPG" Height="30"/>
<Image Name="img2" Source="Images\win2wpf.JPG" Height="30"/>
</StackPanel>
Code Behind:
Setting Image from code:
Need to use
ImageSource to set the images from codebehind.
// Window1.xaml.cs
ImageSourceConverter imgsc = new ImageSourceConverter();
string path = @"Images\win2wpf.JPG";
ImageSource imageSource = (ImageSource)imgsc.ConvertFromString(path);
img1.Source = imageSource;
ProgressBar:
Namespace : System.Windows.Controls.ProgressBar
Designer Code:
<ProgressBar Margin="10,10,0,13" Name="ProgressBar1"
HorizontalAlignment="Left" VerticalAlignment="Top"
Width="170" Height="30" />
Code Behind:
Setting value of Progressbar from code:
// Window1.xaml.cs
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ProgressBar1.Value = 50;
}
Animation in Progressbar:
// Window1.xaml.cs
DoubleAnimation myDoubleAnimation = new DoubleAnimation();
myDoubleAnimation.From = 0;
myDoubleAnimation.To = 300;
myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
myDoubleAnimation.AutoReverse = true;
myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
ProgressBar1.BeginAnimation(ProgressBar.ValueProperty,
myDoubleAnimation);