Skip to content

Instantly share code, notes, and snippets.

@Olwaro
Created December 2, 2013 20:11
Show Gist options
  • Save Olwaro/7757805 to your computer and use it in GitHub Desktop.
Save Olwaro/7757805 to your computer and use it in GitHub Desktop.
Fun with WPF4.5 and Rx
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
namespace waving_progressbars
{
public partial class MainWindow
{
private const int NbBars = 80;
readonly List<ProgressBar> _bars = new List<ProgressBar>();
public MainWindow()
{
InitializeComponent();
// Instanciante some ProgressBars
for (var i = 0; i < NbBars; i++)
{
_bars.Add(new ProgressBar { Height = 10});
Panel.Children.Add(_bars[i]);
}
Observable.Interval(TimeSpan.FromMilliseconds(40)).Subscribe(Wave);
}
public void Wave(long l)
{
for (int i = 0; i < NbBars; i++)
{
var t = Math.Cos((l + i*(100/15)) * (2D / (200D) * Math.PI));
var tmp = i;
Application.Current.Dispatcher.Invoke(() =>
{
_bars[tmp].Value = 50 + t * 50;
});
}
}
}
}
/* View side
<Window x:Class="waving_progressbars.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="Height" Width="525">
<Grid>
<StackPanel Name="Panel" Orientation="Vertical">
</StackPanel>
</Grid>
</Window>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment