Last active
December 18, 2015 12:10
-
-
Save sphingu/5781188 to your computer and use it in GitHub Desktop.
ProcessBar use in WPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------- | |
//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