Global Busy Indicator?

5 posts, 0 answers
  1. Ramjet
    Ramjet avatar
    51 posts
    Member since:
    Jul 2009

    Posted 23 Apr 2012 Link to this post

    Hello,

    From my reading of this line "

    When you are using the RadBusyIndicator control you always have to set its Content property. This will be the content on top of which you want to visualize the RadBusyIndicator control." in this article http://www.telerik.com/help/silverlight/radbusyindicator-getting-started.html I mocked up this quick demo to see if I could use it. WPF app loads a window. In the window is a frame which loads a page. On that page is a button that when clicked puts the thread to sleep for 3 seconds. In that button I get a handle to the parent window and set the IsBusy to true....but it never shows. I've tried numerous variations but I can't get it to work in my project or my mockup??

    MainWindow:

    <Window x:Class="LoadingTest.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <telerik:RadBusyIndicator x:Name="Thnk" IsBusy="false" telerik:StyleManager.Theme="Expression_Dark"  >
                <Frame Name="frm_BigBro" Grid.Row="0" Source="Page1.xaml" SnapsToDevicePixels="True" />
            </telerik:RadBusyIndicator>
        </Grid>
    </Window>

    Main Page cs

    public void StartThinking()
            {
                Thnk.IsBusy = true;
            }
     
            public void StopThinking()
            {
                Thnk.IsBusy = false;
            }


    Page1 XAML

    <Grid>
        <TextBlock Text="My Page" />
        <Button x:Name="Button1" Click="Button1_Click" Width="80" Height="20" />
    </Grid>

    Page1 cs

    private void Button1_Click(object sender, RoutedEventArgs e)
            {
                MainWindow wndow = new MainWindow();
     
                wndow = Window.GetWindow(sender as DependencyObject) as MainWindow;
                wndow.StartThinking();
     
                System.Threading.Thread.Sleep(3000);
     
                wndow.StopThinking();
     
            }

    I'm sure it works so I must be doing something wrong?

    TIA
    JB

  2. Georgi
    Admin
    Georgi avatar
    349 posts

    Posted 26 Apr 2012 Link to this post

    Hi John,

    When you are using Thread.Sleep the UI Thread is blocked and the BusyIndicator can not be displayed. We recommend doing such operation in a separate thread using BackgroundWorker. As an attached file you can find a simple project corresponding to the code you have sent.  Also you can take a look of this online demo.

    Greetings,
    Georgi
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 19 Jun 2012 Link to this post

    Hi,

    this is great, but how does it work without the Button? I click on a Button in the MainWindow, in this MainWindow i have a frame and i want to show the page after it's loaded.

    The main problem is to fill a RadGridView with ItemSource.

    The Busyindicator is runnin well, but i can't bind the ItemSource to the Grid, during backgroundworker ist working. But how can i bind the ItemSource?

    void Form_Loaded:
    this.window = Window.GetWindow(sender as DependencyObject) as MainWindow;           
    this.window.StartThinking();
     
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
    backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandlerbackgroundWorker_RunWorkerCompleted);
    backgroundWorker.RunWorkerAsync();

    void backgroundworker_DoWork:
    // FileList = List<string>
    FileList = winscp.GetFileNameInFolder(AktVerbindung, "spx", false);
    QUELLEGrd.DataContext = FileList;
    -- ERROR --

    Error:
    The calling thread can not access this object because the object is owned by another thread.

    How can i solve this?

    Thanks
    Best Regrds
    Rene
  5. Georgi
    Admin
    Georgi avatar
    349 posts

    Posted 20 Jun 2012 Link to this post

    Hi Rene,

    Form_Loaded should work for you instead of a button click. It seems like the only thing you need to do is use InvokeOnUIThread, in the example it looks like this :

    private void OnBackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                var backgroundWorker = sender as BackgroundWorker;
                backgroundWorker.DoWork -= this.OnBackgroundWorkerDoWork;
                backgroundWorker.RunWorkerCompleted -= OnBackgroundWorkerRunWorkerCompleted;
     
                InvokeOnUIThread(() =>
                {
                    this.IsBusy = false;
                    this.Appointments = new ObservableCollection<Appointment>((IEnumerable<Appointment>)e.Result);
                });
            }

    Can you, please give it a try and let us know if this works for you?


    Regards,
    Georgi
    the Telerik team

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

  6. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 20 Jun 2012 Link to this post

    Hi,

    thanks that's it!

    Regards
    Rene
Back to Top
UI for WPF is Visual Studio 2017 Ready