silverlight 中的busyIndicator 加载控件

来源:互联网 发布:手机淘宝怎么改成好评 编辑:程序博客网 时间:2024/05/21 22:52

XAML代码

<UserControl x:Class="SilverlightApplication9.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="598" d:DesignWidth="825" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">

    <Grid x:Name="LayoutRoot" Background="White" Height="528" Width="743">
        <Canvas Height="506" HorizontalAlignment="Left" Margin="10,10,0,0" Name="canvas1" VerticalAlignment="Top" Width="733">
            <TextBox Canvas.Left="185" Canvas.Top="36" Height="157" Name="textBox1" Width="301" />
            <Button Canvas.Left="293" Canvas.Top="264" Content="填入数据" Height="23" Name="button1" Width="75" Click="button1_Click" />
          
        </Canvas>
        <Canvas Canvas.Left="10" Canvas.Top="10" Name="canvas2" Margin="13,19,0,0"  Background="White" Visibility="Collapsed">
                <toolkit:BusyIndicator Canvas.Left="207" Canvas.Top="211" Height="95"  Name="busyIndicator1" Width="304" BusyContent="正在加载数据,请稍后!" IsBusy="False" />
            </Canvas>
    </Grid>
</UserControl>

 

CS代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;

namespace SilverlightApplication9
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

            busyIndicator1.IsBusy = true;
            textBox1.Text = "123333333333333333333333333333333334566666666666666";
            canvas2.Visibility = Visibility.Visible;
            ThreadPool.QueueUserWorkItem((threadState) =>
            {
                Thread.Sleep(5000);
                Dispatcher.BeginInvoke(() =>
                 canvas2.Visibility = Visibility.Collapsed);
                Dispatcher.BeginInvoke(() =>
                              busyIndicator1.IsBusy = false);
            });
        }
    }
}

 实例下载http://download.csdn.net/detail/bychentufeiyang/3914725