i found a program and am trying to port it from C# to WPF, im doing well so far, but i have a problem with UserControl. I cannot convert it to WPF, since my knowledge is limited. On C# we used OnPaint, on WPF OnRender, i cant get a clue how to implement same UserControl in WPF Here is the code:
public partial class DownloadBar : UserControl
{
public DownloadBar()
{
InitializeComponent();
}
public enum DownloadBarState
{
Setup,
Available,
Playable
}
protected double percent = 0.0f;
[Category("Download Bar Properties")]
[DefaultValue(true)]
public double Value
{
get
{
return percent;
}
set
{
if (value < 0)
value = 0;
else if (value > 100)
value = 100;
percent = value;
this.Invalidate();
}
}
protected DownloadBarState dBarState = DownloadBarState.Setup;
[Category("Download Bar Properties")]
public DownloadBarState BarState
{
get
{
return dBarState;
}
set
{
dBarState = value;
this.Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
switch (dBarState)
{
case DownloadBarState.Setup:
g.DrawImage(Properties.Resources.dbar_setup, 0, 0);
g.DrawImage(Properties.Resources.red_progressbar, 5, 35, (int)((Value / 100) * this.Width), 10);
break;
case DownloadBarState.Available:
g.DrawImage(Properties.Resources.dbar_available, 0, 0);
g.DrawImage(Properties.Resources.yellow_progressbar, 5, 35, (int)((Value / 100) * this.Width), 10);
break;
case DownloadBarState.Playable:
g.DrawImage(Properties.Resources.dbar_playable, 0, 0);
g.DrawImage(Properties.Resources.DownloadProgressBarGreen, 5, 35, (int)((Value / 100) * this.Width), 10);
break;
}
}
}
And here is the second part:
public partial class DownloadProgressBar : UserControl
{
public DownloadProgressBar()
{
InitializeComponent();
}
public enum ProgressBarColor
{
Green,
Blue,
Red,
Yellow
}
protected double percent = 0.0f;
[Category("Behavior")]
[DefaultValue(true)]
public double Value
{
get
{
return percent;
}
set
{
if (value < 0)
value = 0;
else if (value > 100)
value = 100;
percent = value;
progressBarPictureBox.Size = new Size((int)((value / 100) * this.Width), this.Height);
this.Invalidate();
}
}
public void DownloadColor(ProgressBarColor color)
{
switch (color)
{
case ProgressBarColor.Green:
progressBarPictureBox.BackgroundImage = Properties.Resources.DownloadProgressBarGreen;
break;
}
}
}
Read about Invalidate, and that there is no such option in WPF also googled about WPF OnRender, but still have no idea how to do this. Any help is really appreciated!
Here is some screenshots of what im trying to achieve