Blog Content

    티스토리 뷰

    62.SilverLight3 - ProgressBar

    반응형
    ProgressBar
    - 작업 진행 상태를 표시 할 때 많이 사용되는 컨트롤입니다.

    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