- 작업 진행 상태를 표시 할 때 많이 사용되는 컨트롤입니다.
MainPage.xaml |
<Grid x:Name="LayoutRoot" Background="White"> <StackPanel> <TextBlock x:Name="txtTime" Text="시간 : "
FontSize="14" VerticalAlignment="Center"></TextBlock> <ProgressBar x:Name="prsBar" Minimum="0" Maximum="100" Height="30"> </ProgressBar> <Button x:Name="btnGo" Content="오래 걸리는 작업 실행" FontSize="14"> </Button> </StackPanel> </Grid> |
MainPage.xaml.cs |
namespace ProgressBar { public partial class MainPage : UserControl { public
MainPage() { InitializeComponent(); //버튼 이벤트 btnGo.Click += new RoutedEventHandler(btnGo_Click); //진행시간표시 prsBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(prsBar_ValueChanged); } void
prsBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { txtTime.Text = "시간 : " + this.prsBar.Value.ToString(); txtTime.Text += "%"; } void
btnGo_Click(object sender, RoutedEventArgs e) { //비동기 처리(다른 작업 가능하게 함), 내부적으로 처리 //다운로드 또는 프로그레스바 진행시 현재 프로그램과 무관한 다른 스레드에서 //특정 기능 실행 BackgroundWorker
worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.RunWorkerAsync(); } void
worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { this.prsBar.Value
= e.ProgressPercentage; //변경된 값 출력 } void
worker_DoWork(object sender, DoWorkEventArgs e) { int
step = 10; //10씩 증가 int
newValue = 0; while
(newValue < 100) { newValue += step; BackgroundWorker
worker = sender as BackgroundWorker;
worker.ReportProgress(newValue); Thread.Sleep(500); //0.5초 대기 } } } } |
결과화면 |
'Silverlight' 카테고리의 다른 글
64.SilverLight3 - Tab (0) | 2009.12.02 |
---|---|
63.SilverLight3 - Slider (0) | 2009.12.02 |
61.SilverLight3 - ListBox (0) | 2009.12.02 |
60.SilverLight3 - ComboBox (0) | 2009.12.02 |
59.SilverLight3 - ScrollBar (0) | 2009.12.02 |
Comments