wpf BusyIndicator
WPF BusyIndicator
First Adding Reference to WPF Toolkit Extended Assembly
Simple (not busy)
The Common Problem
Solution
Output
Custom Design
Custom Content
First Adding Reference to WPF Toolkit Extended Assembly
Simple (not busy)
<wpfx:BusyIndicator IsBusy="True" > <Grid> <Button>Start Process</Button> </Grid> </wpfx:BusyIndicator>Output
The Common Problem
<wpfx:BusyIndicator x:Name="_busyIndicator" > <Grid> <Button Click="StartProcess" Name="btnStartProcess">Start Process</Button> </Grid> </wpfx:BusyIndicator>
private void StartProcess(object sender, RoutedEventArgs e) { //show BusyIndicator _busyIndicator.IsBusy = true; //long running process for (int i = 0; i < 100; i++) { System.Threading.Thread.Sleep(50); } //hide BusyIndicator _busyIndicator.IsBusy = false; }
Solution
<wpfx:BusyIndicator x:Name="_busyIndicator"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <ListBox x:Name="_listBox" /> <Button Grid.Row="1" Click="StartProcess">Start Process</Button> </Grid> </wpfx:BusyIndicator>
private void StartProcess(object sender, RoutedEventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { List<String> listOfString = new List<string>(); for (int i = 0; i < 10000000; i++) { listOfString.Add(String.Format("Item: {0}", i)); } //use the Dispatcher to delegate the listOfStrings collection back to the UI Dispatcher.Invoke((Action)(() => _listBox.ItemsSource = listOfString)); }; worker.RunWorkerCompleted += (o, ea) => { _busyIndicator.IsBusy = false; }; _busyIndicator.IsBusy = true; worker.RunWorkerAsync(); }
Output
Custom Design
<wpfx:BusyIndicator IsBusy="True" BusyContent="Downloading email..." > <ContentControl Style="{StaticResource SampleContent}"/> </wpfx:BusyIndicator>
Custom Content
<wpfx:BusyIndicator IsBusy="True" DisplayAfter="0"> <wpfx:BusyIndicator.BusyContentTemplate> <DataTemplate> <StackPanel Margin="4"> <TextBlock Text="Downloading Email" FontWeight="Bold" HorizontalAlignment="Center"/> <StackPanel Margin="4"> <TextBlock Text="Downloading message 4/10..."/> <ProgressBar Value="40" Height="15"/> </StackPanel> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0"/> <Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/> </Grid> </StackPanel> </DataTemplate> </wpfx:BusyIndicator.BusyContentTemplate> <wpfx:BusyIndicator.OverlayStyle> <Style TargetType="Rectangle"> <Setter Property="Fill" Value="#ffffeeee"/> </Style> </wpfx:BusyIndicator.OverlayStyle> <wpfx:BusyIndicator.ProgressBarStyle> <Style TargetType="ProgressBar"> <Setter Property="Visibility" Value="Collapsed"/> </Style> </wpfx:BusyIndicator.ProgressBarStyle> <ContentControl Style="{StaticResource SampleContent}"/> </wpfx:BusyIndicator>
wpf BusyIndicator with Custom Content |
wpf BusyIndicator
Reviewed by Bhaumik Patel
on
11:41 PM
Rating: