WPF学习篇 之 星月传说

原创 2007年09月21日 21:23:00

 xaml 文件

<Page x:Class="wpftest.MoonAndSun"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ovt="clr-namespace:BOCO.OssView.Topo;assembly=BOCO.OssView.Topo"
    Title="MoonAndSun"
    >
  <Page.Resources>
    <ContextMenu x:Key="nodeContextMenu" StaysOpen="True">
      <MenuItem Header="{Binding Path=Host}"/>
      <Separator/>
      <MenuItem Header="可拖动" IsCheckable="True" IsChecked="{Binding Path=CanDrag}"/>
      <MenuItem Header="选中" IsCheckable="True" IsChecked="{Binding Path=IsSelected}"/>
      <MenuItem Header="显示" IsCheckable="True" IsChecked="{Binding Path=IsVisible}"/>
    </ContextMenu>
  </Page.Resources>
  <Grid>
    
      <ovt:NetworkPanel Name="plotPanel" Grid.Row="1" Grid.Column="0" />
     
      <ovt:ContainerPanel Grid.Row="1" Grid.Column="0" Name="myContainer" Background="Transparent" />
    </Grid>
</Page>


.cs文件

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BOCO.OssView.Model;
using System.Windows.Threading;
using BOCO.OssView.Topo;

namespace wpftest
{
    /// <summary>
    /// Interaction logic for MoonAndSun.xaml
    /// </summary>

    public partial class MoonAndSun : System.Windows.Controls.Page
    {
        private string mDemoInfo = "星月童话";
        Node sun;
        Node earth;
        Node moon;
        Node halei;
        Network network;
        DispatcherTimer timer;
        Ellipse sunEllipse;
        Ellipse earthEllipse;

        const int radiusX = 280;
        const int radiusY = 150;
        const int earthRadius = 50;
        double theta = Math.PI / 1440;
        int tick = 0;
        static MoonAndSun instance = null;
     
        public MoonAndSun()
        {
            InitializeComponent();
            if (instance == null)
                instance = this;
        }
        public static MoonAndSun Instance()
        {
            if (instance == null)
                instance = new MoonAndSun();
            return instance;
        }
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            sunEllipse = new Ellipse();
            sunEllipse.Stroke = Brushes.Yellow;
            sunEllipse.StrokeThickness = 1;
            sunEllipse.Width = radiusX * 2;
            sunEllipse.Height = radiusY * 2;
            myContainer.Children.Add(sunEllipse);

            earthEllipse = new Ellipse();
            earthEllipse.Stroke = Brushes.Yellow;
            earthEllipse.StrokeThickness = 1;
            earthEllipse.Width = earthRadius * 2;
            earthEllipse.Height = earthRadius * 2;
            myContainer.Children.Add(earthEllipse);


            plotPanel.DataSource = CreateNetwork();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(20);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }
        public Network CreateNetwork()
        {
            string name = "sun";

            sun = new Node();
            sun.CanDrag =false;
            sun.CenterX = -100;
            sun.CenterY = 0;
            sun.Name = name;
            sun.ImageUri = "pack://application:,,,/Images/sun.png";

            name = "earth";
            earth = new Node( );
            earth.CanDrag = true;
            earth.Name = name;
            earth.ImageUri = "pack://application:,,,/Images/earth.png";

            name = "moon";
            moon = new Node( );
            moon.CanDrag = false;
            moon.Name = name;
            moon.ImageUri = "pack://application:,,,/Images/moon.png";

            name = "HaLei";
            halei = new Node();
            halei.CanDrag = true;
            halei.ImageUri = "pack://application:,,,/Images/Star.png";

            name = "network";
            network = new Network( );
            network.Width = 1000;
            network.Height = 500;
            network.ImageUri = "pack://application:,,,/Images/star_small.JPG";
            network.Name = name;
            network.Children.Add(sun);
            network.Children.Add(earth);
            network.Children.Add(moon);
            network.Children.Add(halei);


            return network;
        }

        void timer_Tick(object sender, EventArgs e)
        {
           
            earth.CenterX = radiusX * Math.Cos(theta * tick);
            earth.CenterY = radiusY * Math.Sin(theta * tick);
            PlotPanel.SetCenterX(earthEllipse, earth.CenterX);
            PlotPanel.SetCenterY(earthEllipse, earth.CenterY);
            moon.CenterX = earth.CenterX + earthRadius * Math.Sin(10 * theta * tick);
            moon.CenterY = earth.CenterY + earthRadius * Math.Cos(10 * theta * tick);

            halei.CenterX = earth.CenterX - 10;
            halei.CenterY = earth.CenterY - 200;

            tick++;
        }

    }
}

dll没放上来。yanchanggang@boco.com.cn

星月软件备份文件

  • 2011年12月13日 15:10
  • 32.13MB
  • 下载

Cocos2d-x教程第(1)讲-让我们来学习一些传说中的概念

该文章适合所有想学Cocos2d-x的朋友,但最适合的人群是游戏开发经验及Cocos2d-x使用经验不多的朋友。 1.1 我的Cocos2d-x版本        笔者在写这边文章时,最新...

星月论坛XYLTSF Forum v1.9

  • 2004年09月16日 00:29
  • 601KB
  • 下载

Cocos2d-x教程(1)-让我们来学习一些传说中的概念

该文章适合所有想学Cocos2d-x的朋友,但最适合的人群是游戏开发经验及Cocos2d-x使用经验不多的朋友。 1.1 我的Cocos2d-x版本        笔者在写这边文章时,最新的Cocos...

传说中的《程序猿装B指南》,程序员童鞋们请认真学习

传说中的《程序猿装B指南》,程序员童鞋们请认真学习 一、准备工作 “工欲善其事必先利其器。” 1.电脑不一定要配置高,但是双屏是必须的,越大越好,能一个横屏一个竖屏更好。一个用来查资...
  • xvppdd
  • xvppdd
  • 2011年09月15日 09:24
  • 773

人月传说(7z)

  • 2007年04月01日 11:49
  • 1.04MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:WPF学习篇 之 星月传说
举报原因:
原因补充:

(最多只允许输入30个字)