C1ProgressIndicator is one of the new controls added in the latest Studio for WPF 2014 V3 release. This control can display the progress while a process is being executed. One example is while loading data or other documents in a datacentric application. C1ProgressIndicator is very useful in a multi-threaded environment where multiple threads are executing at the same time and for putting a thread into wait state or sleep state. In this tutorial, you will learn how to use C1ProgessIndicator.
Here are the steps to add C1ProgressIndicator into your project:-
C1ProgressIndicator1.IsActive=true;
Now, lets take up an example to demonstrate how to use C1ProgressIndicator :- Step1. First of all, you need a container control to show C1ProgressIndicator so here we have used a C1Window control to display the C1ProgressIndicator. Step2. C1ProgressIndicator can display any custom text, here we are showing the progress percentage while the data is loading. Step3. Now, this C1Window control is displayed until the data from C1DataGrid or C1Chart is completely loaded. Therefore, we have used the Threading concept for inter-dependent processing of Data Loading and the C1ProgressIndicator. Step4. C1Window gets automatically closed as soon as the data gets loaded into the C1DataGrid or C1Chart. Here is the code snippet for the same:-
public void ShowProgressIndicator(String msg)
{
var w = new C1Window();
StackPanel MyStackPanel = new StackPanel();
TextBlock MyPercentProgress = new TextBlock();
C1ProgressIndicator pi = new C1ProgressIndicator();
pi.Header = msg;
pi.Foreground = new SolidColorBrush(Colors.Green);
MyStackPanel.Children.Add(MyPercentProgress);
MyStackPanel.Children.Add(pi);
w.Content = MyStackPanel;
w.Width = 300;
w.Height = 150;
w.CenterOnScreen();
w.ShowModal();
Thread t1 = new Thread(new ThreadStart(() =>
{
for (int i = 1; i <= 100; i++) { this.Dispatcher.BeginInvoke(new Action(() =>
{
int counter = i;
string myString = counter.ToString();
MyPercentProgress.Text = myString + "% Data Loaded";
pi.IsActive = true;
if (counter == 100)
{
w.Close();
this.c1Chart.Visibility = Visibility.Visible;
this.c1DataGrid.Visibility = Visibility.Visible;
}
}));
Thread.Sleep(30);
}
}));
t1.Start();
pi.IsActive = false;
}
See it in action!! Download Sample