This is a migrated thread and some comments may be shown as answers.

BusyIndicator after login button pressed

5 Answers 333 Views
BusyIndicator
This is a migrated thread and some comments may be shown as answers.
Andrea Ferrari
Top achievements
Rank 1
Andrea Ferrari asked on 08 Jul 2010, 12:30 PM
Hi.
I'm trying to use BusyIndicator. I want to start it when the button login is pressed, so I've setted the property IsBusy to false when the windows startup and then to true when the button is pressed.
I'm working with the pattern MVVM so I've binded the property IsBusy with a property in the viewmodel initially setted to false and then to true when the button is pressed.

The problem is that the BusyIndicator is on the top of the window also if its property IsBusy is setted top false.

What I've to do?

Thanks and regards
Andrea Ferrari

5 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 13 Jul 2010, 09:49 AM
Hi Andrea Ferrari,

Thank you for your interest in our products.

Could you please double check if the PropertyChanged event is firing after you are setting the property in the ViewModel.

If you still experience the issue could you please try to reproduce it in a sample project and send it to us. In that way we will be able to assist you in the best manner.

Greetings,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Garry Clark
Top achievements
Rank 1
answered on 11 Aug 2010, 02:31 PM
Konstantina,
I am having a similar issue that I have not been able to resolve. I am also using MVVM along with Prism and have two properties on my ViewModel, IsBusy and BusyText.

I am trying to set the busy indicator to active on the Shell view model from the bootstrapper and pass some informative message along to the user while everything loads. I can set the 2 properties and see the PropertyChanged event fire, but the BusyIndicator does not display until the Shell has finished loading. 

This lead me to believe I needed to use a BackgroundWorker, but my efforts with that have also failed. I can open a ticket and upload a simple project to demonstrate what I am talking about if need be, but I was hoping maybe you had some insight as to what is needed to get this scenario to work. Below is the viewmodel and bootstrapper I currently have.

ShellViewModel
using EliteExtender.Composite.Extensions;
using EliteExtender.Composite.Extensions.Logger;
using EliteExtender.Composite.Extensions.ViewModels;
using EliteExtender.Infrastructure.Services;
using EliteExtender.Shell.Properties;
using EliteExtender.Shell.Views;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Unity;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
  
namespace EliteExtender.Shell.ViewModels
{
    internal class ShellViewModel : ViewModelBase<IShellView>
    {
        private static readonly PropertyInfo StatusMessageProperty = TypeManager.GetProperty<ShellViewModel>(x => x.StatusMessage); 
        private static readonly PropertyInfo BusyTextProperty = TypeManager.GetProperty<ShellViewModel>(x => x.BusyText); 
        private static readonly PropertyInfo IsBusyProperty = TypeManager.GetProperty<ShellViewModel>(x => x.IsBusy); 
          
        IEventAggregator aggregator;
        IUnityContainer container;
        EnterpriseLibraryLogger loggerService;
        private string statusMessage = "Ready";
  
        public ShellViewModel(IUnityContainer container, IShellView view, IEventAggregator aggregator, EnterpriseLibraryLogger loggerService)
            : base(view)
        {
            this.container = container;
            this.loggerService = loggerService;
            this.aggregator = aggregator;
  
            ClosingCommand = new RelayCommand(WindowClosing);
           //Log Successful Load
            loggerService.Log("Elite Extender Loaded", Microsoft.Practices.Composite.Logging.Category.Info, Microsoft.Practices.Composite.Logging.Priority.Low, 200, aggregator);
        }
  
        public string HeaderInfo
        {
            get { return Resources.Title; }
        }
  
        public ImageSource HeaderIcon
        {
            get { return new BitmapImage(ResourceService.GetPackUri("Resources/EliteExtender.png")); }
        }
  
        public ICommand ClosingCommand { get; private set; }
        private void WindowClosing(object parameter)
        {
            EliteExtender.Infrastructure.Properties.Settings.Default.Save();
            Application.Current.Shutdown();
        }
  
        public string StatusMessage
        {
            get { return statusMessage; }
            set
            {
                if (statusMessage != value)
                {
                    statusMessage = value;
                    RaisePropertyChanged(StatusMessageProperty);
                }
            }
        }
  
        private string busyText;
        public string BusyText
        {
            get {return busyText;}
            set
            {
                busyText=value;
                //OnPropertyChanged("BusyText");
                RaisePropertyChanged(BusyTextProperty);
            }
        }
  
        private bool isBusy;
        public bool IsBusy
        {
            get { return isBusy; }
            set
            {
                isBusy = value;
                //OnPropertyChanged("IsBusy");
                RaisePropertyChanged(IsBusyProperty);
            }
        }
  
        public void Show()
        {
            View.ShowView();
        }
    }
}
 
Bootstrapper
using EliteExtender.Composite.Extensions;
using EliteExtender.Composite.Extensions.Catalogs;
using EliteExtender.Composite.Extensions.Logger;
using EliteExtender.Shell.ViewModels;
using EliteExtender.Shell.Views;
using Microsoft.Practices.Composite.Logging;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Presentation.Regions;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using Microsoft.Practices.Unity;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using Telerik.Windows.Controls;
using Category = Microsoft.Practices.Composite.Logging.Category;
  
namespace EliteExtender.Shell
{
    public class Bootstrapper : UnityBootstrapper
    {
        #region Prism v4
        private readonly EnterpriseLibraryLogger logger = new EnterpriseLibraryLogger();
        private ShellViewModel presenter;
        private BackgroundWorker worker = new BackgroundWorker();
        private string busytext = "Working...";
        private bool isbusy = true;
  
        /// <summary>
        /// Creates the shell or main window of the application.
        /// </summary>
        /// <returns>The shell of the application.</returns>
        /// <remarks>
        /// If the returned instance is a <see cref="DependencyObject"/>, the
        /// <see cref="Bootstrapper"/> will attach the default <seealso cref="Microsoft.Practices.Composite.Regions.IRegionManager"/> of
        /// the application in its <see cref="Microsoft.Practices.Composite.Presentation.Regions.RegionManager.RegionManagerProperty"/> attached property
        /// in order to be able to add regions by using the <seealso cref="Microsoft.Practices.Composite.Presentation.Regions.RegionManager.RegionNameProperty"/>
        /// attached property from XAML.
        /// </remarks>
        protected override DependencyObject CreateShell()
        {
            worker.DoWork += this.WorkerDoWork;
            worker.RunWorkerCompleted += WorkerRunWorkerCompleted;
  
            presenter = Container.Resolve<ShellViewModel>();
  
            presenter.BusyText = "Test";
            presenter.IsBusy = true;
              
            return presenter.View as DependencyObject;
        }
  
        /// <summary>
        /// Initializes the shell.
        /// </summary>
        /// <remarks>
        /// The base implemention ensures the shell is composed in the container.
        /// </remarks>
        protected override void InitializeShell()
        {
            //log to queue
            logger.QueueLog(Properties.Resources.InitializingShell, Category.Info, Priority.Low);           
            base.InitializeShell();
  
            Application.Current.MainWindow = (Window)this.Shell;
            Application.Current.MainWindow.Show();            
        }
  
        /// <summary>
        /// Create the <see cref="ILoggerFacade"/> used by the bootstrapper.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// The base implementation returns a new TextLogger.
        /// </remarks>
        protected override ILoggerFacade CreateLogger()
        {
            // Because the Shell is displayed after most of the interesting boostrapper work has been performed,
            // this bootstrapper uses a special logger class to hold on to early log entries and display them 
            // after the UI is visible.
            return this.logger;
        }
  
        /// <summary>
        /// Configures the <see cref="IUnityContainer"/>. May be overwritten in a derived class to add specific
        /// type mappings required by the application.
        /// </summary>
        protected override void ConfigureContainer()
        {
            //log to queue
            logger.QueueLog(Properties.Resources.ConfiguringContainerBegun, Category.Info, Priority.Low);           
  
            base.ConfigureContainer();
  
            Container.AddExtension(new EnterpriseLibraryCoreExtension());
  
            Container.RegisterType<IShellView, ShellView>();
            //container.RegisterType<IMessageService, MessageService>(new ContainerControlledLifetimeManager());
            //container.RegisterType<IShowAboutView, ShowAboutViewService>(new ContainerControlledLifetimeManager());
  
            //Registers the instance of our ILoggerFacade implementation 
            Container.RegisterInstance<EnterpriseLibraryLogger>(this.logger,new ContainerControlledLifetimeManager());
  
            //log to queue
            logger.QueueLog(Properties.Resources.ConfiguringContainerFinished, Category.Info, Priority.Low);            
        }
  
        protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
        {
            RegionAdapterMappings regionAdapterMappings = base.ConfigureRegionAdapterMappings();
            if (regionAdapterMappings != null)
            {
                regionAdapterMappings.RegisterMapping(typeof(RadToolBar), Container.Resolve<RadToolBarTrayRegionAdapter>());
                regionAdapterMappings.RegisterMapping(typeof(RadToolBarTray), Container.Resolve<RadToolBarTrayRegionAdapter>());
                regionAdapterMappings.RegisterMapping(typeof(RadPaneGroup), Container.Resolve<RadPaneGroupRegionAdapter>());
                regionAdapterMappings.RegisterMapping(typeof(RadRibbonBar), Container.Resolve<RadRibbonBarRegionAdapter>());
            }
  
            return regionAdapterMappings;
        }
  
        /// <summary>
        /// Returns the module catalog that will be used to initialize the modules.
        /// </summary>
        /// <returns>
        /// An instance of <see cref="IModuleCatalog"/> that will be used to initialize the modules.
        /// </returns>
        /// <remarks>
        /// When using the default initialization behavior, this method must be overwritten by a derived class.
        /// </remarks>
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new AggregateModuleCatalog();
        }
  
        protected override void ConfigureModuleCatalog()
        {
            //Create a MultipleDirectoryCatalog that scans the directory of Modules located in the same directory as the .exe of the App.
            string modulePath = Path.GetFullPath("Modules");
            if (!System.IO.Directory.Exists(modulePath))
            {
                System.IO.Directory.CreateDirectory(modulePath);
            }
            MultipleDirectoryModuleCatalog directoryCatalog = new MultipleDirectoryModuleCatalog() { ModulePath = modulePath };
            //Log to queue
            logger.QueueLog(String.Format(Properties.Resources.ModulesLoadingBegun, modulePath), Category.Info, Priority.Low);
           //Add DirectoryCatalog to catalog collection
            ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(directoryCatalog); 
            //log to queue
            logger.QueueLog(Properties.Resources.ModulesLoadingFinished, Category.Info, Priority.Low);           
        }
  
        void WorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
              
        }
  
        private void WorkerDoWork(object sender, DoWorkEventArgs e)
        {
            presenter.BusyText = busytext;
            presenter.IsBusy = isbusy;
        }
        #endregion
    }
}

0
Konstantina
Telerik team
answered on 16 Aug 2010, 09:26 AM
Hello Garry,

Thank you for your participation in the discussion.

Could you please review the following online demo. It illustrates the use of the RadBusyIndicator with the BackgroundWorker class.

If that doesn't help you could you please send us a sample project in order to assist you in a timely manner.

Greetings,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Prasad
Top achievements
Rank 1
answered on 16 Aug 2011, 10:30 AM
The Online Demo what u had given works fine if we set IsBusy property of RadBusyIndicator in constructor of ViewModel. But if we set it in call of Button Click Method(in ViewModel) it is not working. Please give us some solution so that we can use RadBusyIndicator in our MVVM project for fetching and Saving Data.

Regards
Prasad Thakur.
0
Ivo
Telerik team
answered on 18 Aug 2011, 05:16 PM
Hello Prasad,

I am not sure I completely understood your scenario. Could you please send us a sample project demonstrating this issue? It would definitely help us resolving it..

Kind regards,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
BusyIndicator
Asked by
Andrea Ferrari
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Garry Clark
Top achievements
Rank 1
Prasad
Top achievements
Rank 1
Ivo
Telerik team
Share this question
or