Skip to content

Instantly share code, notes, and snippets.

@sphingu
Last active December 18, 2015 12:10
Show Gist options
  • Save sphingu/5781188 to your computer and use it in GitHub Desktop.
Save sphingu/5781188 to your computer and use it in GitHub Desktop.
ProcessBar use in WPF
-------------------------------------------
//How To use Processbar in WPF
-------------------------------------------
<ProgressBar Name="PbMain" Margin="3" Height="30" Width="400" />
-------------------------------------------
//Code Behind
-------------------------------------------
public partial class MainWindow
{
//Create a Delegate that matches the Signature of the ProgressBar's SetValue method
private delegate void UpdateProgressBarDelegate(DependencyProperty dp, Object value);
readonly UpdateProgressBarDelegate _updatePbDelegate;
public void DoProcess()
{
//Initialize Processbar
pbMain.Maximum = 100;
pbMain.Minimum = 0;
pbMain.Value = 0;
for(int i=0;i<100;i++)
{
pbMain.Value++;
Dispatcher.Invoke(_updatePbDelegate,
System.Windows.Threading.DispatcherPriority.Background,
new object[] { System.Windows.Controls.Primitives.RangeBase.ValueProperty, pbMain.Value });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment