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();

     

  • 相关阅读:
    AIX root用户密码丢失怎么办?
    Oracle 11g Grid Infrastructure 卸载
    Failed to create a peer profile for Oracle Cluster GPnP. gpnptool rc=32512
    管理 IBM AIX 中的用户
    vbox克隆文件的路径如何修改?默认它生成在C盘,怎么修改?
    Oracle_dataguard__11G_配置与维护手册
    AIX管理员常用命令
    如何让你的SQL运行得更快
    ORA00604: 递归 SQL 级别 1 出现错误,ORA01000: 超出打开游标的最大数
    Adobe Acrobat 9.0“ PDFMaker无法找到Adobe PDF Printer 的打印驱动程序”解决办法
  • 原文地址:https://www.cnblogs.com/randylee/p/1791227.html
Copyright © 2011-2022 走看看