Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:dotnet:adorner_layer [2011/01/10 12:44]
smayr
swdev:dotnet:adorner_layer [2011/01/10 12:47] (current)
smayr [Loading Adorner]
Line 155: Line 155:
 Get Adorner Layer of a control, then add adorner: Get Adorner Layer of a control, then add adorner:
 <code csharp> <code csharp>
 +using System;
 +using System.Collections.Generic;
 +using System.Linq;
 +using System.Text;
 +using System.Windows;
 +using System.Windows.Controls;
 +using System.Windows.Data;
 +using System.Windows.Documents;
 +using System.Windows.Input;
 +using System.Windows.Media;
 +using System.Windows.Media.Imaging;
 +using System.Windows.Shapes;
  
 +namespace LoadingAdorner
 +{
 +    /// <summary>
 +    /// Interaction logic for DemoPage.xaml
 +    /// </summary>
 +    public partial class DemoPage : Window
 +    {
 +        DemoPageController controller = new DemoPageController();
 +
 +        public DemoPage()
 +        {
 +            DataContext = controller.Data;
 +            InitializeComponent();
 +
 +            AttachLoadingAdorner();
 +        }
 +
 +        private void AttachLoadingAdorner()
 +        {
 +            // Create "Loading" adorner
 +            LoadingAdorner loading = new LoadingAdorner(mainPane);
 +            loading.FontSize = 15;
 +            loading.OverlayedText = "loading...";
 +            loading.Typeface = new Typeface(FontFamily, FontStyles.Italic, 
 +                FontWeights.Bold, FontStretch);
 +            Binding bind = new Binding("SearchInProgress");
 +            bind.Source = controller;
 +            bind.Converter = new VisibilityConverter();
 +            loading.SetBinding(LoadingAdorner.VisibilityProperty, bind);
 +            
 +            // Get mainPane's AdornerLayer and add new "Loading" adorner
 +            AdornerLayer.GetAdornerLayer(mainPane).Add(loading);  
 +        }
 +    }
 +
 +    /// <summary>
 +    /// Converter that converts a bool to a Visibility status
 +    /// </summary>
 +    public class VisibilityConverter : IValueConverter
 +    {
 +        #region IValueConverter Members
 +
 +        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 +        {
 +            return (bool)value ? Visibility.Visible : Visibility.Collapsed;
 +        }
 +
 +        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 +        {
 +            throw new NotImplementedException();
 +        }
 +
 +        #endregion
 +    }
 +
 +}
 </code> </code>