Sonntag, 5. Juni 2011

Windows Phone: Mango ProgressIndicator in SystemTray

With Mango for Windows Phone we have some cool changes for the system tray control. SystemTray is a DependencyObject and because Mango is now running on SL4, DependencyObject can be data bound. The other feature for the System Tray coming with Mango is a ProgressIndicator which can used to display progress on async operations.

More details and sample code about the new ProgressIndicator in the System Tray you can find here: System Tray Progress Indicator - Jaime Rodriguez - Site Home - MSDN Blogs

Data Binding of ProgressIndicator

Sample for programmatically data binding of the ProgressIndicator in the Loaded-Event of the page:

this.Loaded += ( x, y ) => 
    {
        var progressIndicator = SystemTray.ProgressIndicator;
        if (progressIndicator != null)
        {
            return;
        }
        progressIndicator = new ProgressIndicator();
                        
        SystemTray.SetProgressIndicator(this, progressIndicator);
                         
        var binding = new Binding("IsChecked") { Source = this.ProgressIndicatorIsVisible };
        BindingOperations.SetBinding(progressIndicator, ProgressIndicator.IsVisibleProperty, binding); 
                        
        binding = new Binding("IsChecked") { Source = this.ProgressIndicatorIsIndeterminate };
        BindingOperations.SetBinding(progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding); 
                        
        binding = new Binding("Text") { Source = this.ProgressIndicatorText };
        BindingOperations.SetBinding(progressIndicator, ProgressIndicator.TextProperty, binding);
 
        binding = new Binding("Value") { Source = this.ProgressIndicatorValueSlider };
        BindingOperations.SetBinding(progressIndicator, ProgressIndicator.ValueProperty, binding);
    } ;              

Updated: Data Binding over declaration

Many thanks to a colleague, who give me the tip that data binding for SystemTray is also possible with XAML declaration.

See sample here: http://danielvaughan.org/post/Binding-the-WP7-ProgressIndicator-in-XAML.aspx

Keine Kommentare:

Kommentar veröffentlichen