zoukankan      html  css  js  c++  java
  • 一起学Windows Phone7开发(十三.九 UserControl控件)

        Phone7提供的控件都是一些基本的控件,这远远是无法满足开发需要的,这就需要用到这个用户控件,来自定义所需要的控件。比如:TreeViewWaiting等都是Phone7中没有的。另外这也是与silverlight不的地方,在silverlight中,所有的页面都是继承自UserControl,而Phone7的页面却是继承自PhoneApplicationPage

    下面制作一个有动画的简单的WaitingBox:

    1.       创建:UserControl继承了UserControl这个控件类,也就是说控件该有的属性、方法就都有了,那自已需要的,就要自已扩展了。

    2.       示例XAML

    <Popup x:Name="WaitingWnd" IsOpen="False">

           <Grid x:Name="LayoutRoot" Background="Transparent">

                <TextBlock Height="44" HorizontalAlignment="Left" Margin="0,144,0,0" Name="textBlock1" Text="请等待….." VerticalAlignment="Top" Foreground="Gray" Width="200" FontSize="32"  TextAlignment="Center"/>

                <Image Height="150" HorizontalAlignment="Left" Margin="22,6,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="150" />

            </Grid>

        </Popup>

     

    3.       示例代码:

     public partial class WaitingBox : UserControl

        {

     

     DispatcherTimer Timer = null;

     int Count = 0;

    public double Speed { get; set; }

     

    public WaitingBox()

    {

    InitializeComponent();

    }

     

    private void UserControl_Loaded(object sender, RoutedEventArgs e)

    {

                Timer = new DispatcherTimer();

               Timer.Interval = TimeSpan.FromMilliseconds(Speed);

            Timer.Tick += new EventHandler(Timer_Tick);

              

    }

     

    void Timer_Tick(object sender, EventArgs e)

    {

          this.image1.Source = new BitmapImage(new Uri("Images/" + Count + ".png", UriKind.Relative));

           Count =( Count == 7 ? 0 : Count+1);

    }

     

    public void WaitingBegin()

    {

         Timer.Start();

         WaitingWnd.IsOpen = true;

    }

     

    public void WaitingEnd()

    {

        Timer.Stop();

        WaitingWnd.IsOpen = false;

    }

    }

    4.       调用:

     

    <my:WaitingBox Height="200" HorizontalAlignment="Left" Margin="152,147,0,0" x:Name="waitingBox1" VerticalAlignment="Top" Width="200"  Speed="100"/>

     

    waitingBox1.WaitingBegin();

    waitingBox1.WaitingEnd();

     

  • 相关阅读:
    【PHP】window系统中设置计划任务,定时调用某接口
    【php】在laravel中使用 easy-wechat实现企业付款到零钱
    【转载】laravel中使用WangEditor及多图上传
    [PHP] curl: (60) SSL certificate problem: unable to get local issuer certificate
    阿里云服务器win10 访问服务器图片资源提示 401
    【PHP】创瑞短信接口
    C#中Lock锁的对象选择问题
    TCP三次握手,四次挥手异常情况(坑)
    C# Hashtable、HashSet和Dictionary的区别
    浅析C# Dictionary实现原理
  • 原文地址:https://www.cnblogs.com/randylee/p/1791227.html
Copyright © 2011-2022 走看看