さらに寄り道してSilverlightでブログパーツを作る

美女Linuxブログパーツ作成企画

Siverlight 4 でブログパーツを作るとこんな感じ。

20101117_03.jpg

<サンプル>

移植はすんなりできそうです。

<コード>


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

        int count = 10000;
        int bcount = 0;

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            myDispatcherTimer.Interval = new TimeSpan(0, 0, 0,1, 0);
            myDispatcherTimer.Tick += new EventHandler(Each_Tick);
            myDispatcherTimer.Start();
        }

        public void Each_Tick(object o, EventArgs sender)
        {
            count++;
            if (count > 15)
            {
                count = 0;
                bcount++;
                if (bcount > 5)
                {
                    bcount = 0;
                }
                Uri uri = new Uri("http://moonmile.net/images/photo00"+bcount+".png",
                    UriKind.RelativeOrAbsolute);
                ImageSource source = new BitmapImage(uri);
                bimage.Source = source;
            }
            settime();
        }
        public void settime()
        {
            DateTime now = DateTime.Now;

            string year = now.ToString("yyyy");
            string[] months = new string[] { "Jan", "Fev", "Mar", "Apl", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
            string mon = months[ now.Month-1];
            string day = now.ToString("dd");
            string time = now.ToString("HH:mm:ss");

            bdateyear.Content = year;
            bdatemon.Content = mon;
            bdateday.Content = day;
            bdatetime.Content = time;
        }
    }
}

コード的には、これが一番すっきり…というか得意分野だけなんですが。

カテゴリー: 開発, ブログパーツ パーマリンク