.Net Mirco Framework 2007技术大会

简介: 最近公司很多项目都有大量嵌入式设备使用,由于WinCE系统相对较大,对硬件平台要求过高,所以对.Net MF一直比较关注。今天总算大开眼界了

.Net Mirco Framework 2007技术大会

2006年在《程序员》杂志上通过看马宁的专栏文章,第一次知道了.Net MF。一年后的今天终于近距离地接触了.Net Mirco Frmaework,对MF有了一定的感性认识。

最近公司很多项目都有大量嵌入式设备使用,由于WinCE系统相对较大,对硬件平台要求过高,所以对.Net MF一直比较关注。今天总算大开眼界了。
image.png
微软公司的Colin Miller和Digi公司的John Leier在上午的演讲拉开了.Net MF序幕,针对嵌入式领域,一个从软件角度进行阐述,另一个从硬件平台角度进行呼应,一软一硬,二者强强联合,恐怕未来嵌入式智能设备一半以上的项目开发要被其收入囊中了。下午的中文演讲给人感觉有些干瘪,两三个演讲,平均短短十几分钟就草草收场。后来微软公司杜伟的演讲,从VS2005一行行难以看清的代码,到一个个令人惊艳的样例把MF开发技术推向最前台。
image.png
Digi公司很是有魄力,免费送出15套开发套件(5个作为回答问题的奖品,10个抽奖),自己即没有回答问题的勇气,也没有好的运气,只好剩下羡慕的份了。

最后为每个人送出的1G优盘(类似微软今年MVP大礼包中的优盘)很有分量,不仅是1G的容量,并且里面竟然把所有的幻灯片拷贝其中,更没有想到的是,MF 的SDK也在里面,真棒!

回到家迫不及待装了一份MF SDK(MicroFrameworkSDK.MSI 区区只有5998 kb,强!),有模拟器,也有示例。
image.png
其中几个示例不知道为什么编译成功,就是运行失败,对第二示例比较感兴趣,可以绘制图形,并且可以贴图。
image.png
image.png
image.png
相关代码如下:

// Copyright (C) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Shapes;

using PresentationDemo;


//////////////////////////////////////////////////////////////////////////////


public sealed class MyApp : Application {
   // This static field prevents the object from being GC'd
   private static GpioButtonInputProvider s_gpioInputProvider;

   public Font NinaBFont;
   public Font SmallFont;
   public Bitmap Snowflake;

   private MyApp() {
      // Initialize the Buttons/Pins dispatcher
      s_gpioInputProvider = new GpioButtonInputProvider(this.Dispatcher, null);

      // Load some resources
      NinaBFont = Resources.GetFont(Resources.FontResources.NinaBFont);
      SmallFont = Resources.GetFont(Resources.FontResources.SmallFont);
      Snowflake = Resources.GetBitmap(Resources.BitmapResources.Snowflake);
   }

   protected override void OnStartup(EventArgs e) {
      // Create and set the application's main window
      this.MainWindow = new MainMenuWindow(this);
      base.OnStartup(e);
   }

   public void GoHome() {
      Buttons.Focus(this.MainWindow); // Set focus back to the main window
   }

   public static void Main() {
      new MyApp().Run();   // Start the app's main window
   }
}


//////////////////////////////////////////////////////////////////////////////


// This is the base class of all our windows; it makes every window visible, 
// sets the window's size to the full size of the LCD, and give the window focus
internal class PresentationWindow : Window {
   protected MyApp m_app;

   protected PresentationWindow(MyApp app) {
      m_app = app;

      // Make the window visible and the size of the LCD
      this.Visibility = Visibility.Visible;
      this.Width = SystemMetrics.ScreenWidth;
      this.Height = SystemMetrics.ScreenHeight;
      Buttons.Focus(this); // Set focus to this window
   }

   protected override void OnButtonDown(ButtonEventArgs e) {
      // Remove this window form the Window Manager
      this.Close();

      // When any button is pressed, go back to the Home page
      m_app.GoHome();
   }
}

//////////////////////////////////////////////////////////////////////////////


internal sealed class MainMenuWindow : PresentationWindow {
   private ListBox m_listbox;

   public ListBox MainListBox { get { return m_listbox; } }

   public MainMenuWindow(MyApp app)
      : base(app) {

      Color instructionTextColor = ColorUtility.ColorFromRGB(192, 192, 192);
      Color backgroundColor = ColorUtility.ColorFromRGB(26, 118, 183);  
      Color unselectedItemColor = ColorUtility.ColorFromRGB(192, 192, 255);   // Unselected listbox item color
      Color selectedItemColor = Colors.White;                                 // Selected listbox item color

      // The Main window contains a veritcal StackPanel
      StackPanel panel = new StackPanel(Orientation.Vertical);
      this.Child = panel;

      // The top child contains text with instructions
      TextFlow textflow = new TextFlow();
      textflow.TextAlignment = TextAlignment.Center;
      textflow.Visibility = Visibility.Visible;
      textflow.TextRuns.Add(
         new TextRun(Resources.GetString(Resources.StringResources.SelectAnItemFromBelow),
         app.NinaBFont, instructionTextColor));
      panel.Children.Add(textflow);

      // Add a blank line to the stack
      panel.Children.Add(textflow = new TextFlow());
      textflow.TextRuns.Add(" ", app.NinaBFont, instructionTextColor);
      textflow.Visibility = Visibility.Visible;

      // The next child contains a listbox with options
      m_listbox = new ListBox();

      // Prepare the listbox
      Buttons.Focus(m_listbox);
      panel.Children.Add(m_listbox);
      this.Background = m_listbox.Background = new SolidColorBrush(backgroundColor);

      m_listbox.SelectionChanged += delegate(Object sender, SelectionChangedEventArgs e) {
         Int32 previousSelectedIndex = e.PreviousSelectedIndex;
         if (previousSelectedIndex != -1) {  // If there was a previous index
            // Change previously-selected listbox item color to unselected color
            ((Text)m_listbox.Items[previousSelectedIndex].Child).ForeColor = unselectedItemColor;
         }

         // Change newly-selected listbox item color to selected color
         ((Text)m_listbox.Items[e.SelectedIndex].Child).ForeColor = selectedItemColor;
      };

      // Add the items to the listbox
      foreach (String s in new String[] { "Vertical Stack", "Horizontal Stack", "Canvas", "Diagonal" }) {
         Text text = new Text(m_app.NinaBFont, s + " Panel Demo");
         text.ForeColor = unselectedItemColor;
         text.TextAlignment = TextAlignment.Center;
         text.Width = this.Width;
         ListBoxItem lbi = new ListBoxItem();
         lbi.Background = m_listbox.Background;
         lbi.Child = text;
         m_listbox.Items.Add(lbi);
      }
      m_listbox.SelectedIndex = 0;

      // Add a blank line in the stack
      panel.Children.Add(textflow = new TextFlow());
      textflow.TextRuns.Add(" ", app.NinaBFont, instructionTextColor);
      textflow.Visibility = Visibility.Visible;

      // The bottom child contains text with return instructions
      textflow = new TextFlow();
      textflow.TextAlignment = TextAlignment.Center;
      textflow.Visibility = Visibility.Visible;
      textflow.TextRuns.Add(
         new TextRun("(After viewing a Panel Demo, hit Enter to return to this screen)",
         app.NinaBFont, instructionTextColor));
      panel.Children.Add(textflow);
   }

   protected override void OnButtonDown(ButtonEventArgs e) {
      // If <Enter> button is pressed, go into the selected demo
      if (e.Button == Button.Select) {
         switch (MainListBox.SelectedIndex) {
            case 0:  // Vertical Stack Panel Demo
               new StackPanelDemo(m_app, Orientation.Vertical);
               break;
            case 1:  // Horizontal Stack Panel Demo
               new StackPanelDemo(m_app, Orientation.Horizontal);
               break;
            case 2:  // Canvas Panel Demo
               new CanvasPanelDemo(m_app);
               break;
            case 3:  // Diagonal Panel Demo
               new DiagonalPanelDemo(m_app);
               break;
         }
      }

      // Don't call base implementation (base.OnButtonDown) or we'll go back Home
   }

   protected override void OnGotFocus(FocusChangedEventArgs e) {
      // Whenever this window gets focus, it gives it to its listbox
      Buttons.Focus(m_listbox);
      base.OnGotFocus(e);
   }
}


//////////////////////////////////////////////////////////////////////////////


internal sealed class StackPanelDemo : PresentationWindow {
   // This class shows how to build your own shape drawing in a DrawingContext
   private sealed class Cross : Shape {
      public Cross() { }

      public override void OnRender(DrawingContext dc) {
         // Draw a line from top, left to bottom, right
         dc.DrawLine(base.Stroke, 0, 0, Width, Height);

         // Draw a line from top, right to bottom, left
         dc.DrawLine(base.Stroke, Width, 0, 0, Height);
      }
   }

   public StackPanelDemo(MyApp app, Orientation orientation)
      : base(app) {
      StackPanel panel = new StackPanel(orientation);
      this.Child = panel;
      panel.Visibility = Visibility.Visible;

      Shape[] shapes = new Shape[] {
         new Ellipse(),
         new Line(),
         new Polygon(new Int32[] { 0, 0,    50, 0,    50, 50,    0, 50 }), // A Square
         new Rectangle(),
         new Cross() // Our own custom shape
      };

      for (Int32 x = 0; x < shapes.Length; x++) {
         Shape s = shapes[x];
         s.Fill = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 255, 0));
         s.Stroke = new Pen(Color.Black, 2);
         s.Visibility = Visibility.Visible;
         s.HorizontalAlignment = HorizontalAlignment.Center;
         s.VerticalAlignment = VerticalAlignment.Center;
         s.Height = Height - 1;
         s.Width = Width - 1;

         if (panel.Orientation == Orientation.Horizontal)
            s.Width /= shapes.Length;
         else
            s.Height /= shapes.Length;

         panel.Children.Add(s);
      }
   }
}


//////////////////////////////////////////////////////////////////////////////


internal sealed class CanvasPanelDemo : PresentationWindow {
   public CanvasPanelDemo(MyApp app)
      : base(app) {
      Canvas canvas = new Canvas();
      this.Child = canvas;
      this.Background = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 255, 255));

      for (Int32 x = 0; x < Width; x += Width / 4) {
         for (Int32 y = 0; y < Height; y += Height / 4) {
            Text text = new Text(m_app.SmallFont, " (" + x + "," + y + ")");
            Canvas.SetLeft(text, x);
            Canvas.SetTop(text, y);
            canvas.Children.Add(text);
         }
      }
   }
}


//////////////////////////////////////////////////////////////////////////////


internal sealed class DiagonalPanelDemo : PresentationWindow {
   public DiagonalPanelDemo(MyApp app)
      : base(app) {
      DiagonalPanel panel = new DiagonalPanel();
      this.Child = panel;
      this.Background = new LinearGradientBrush(
         ColorUtility.ColorFromRGB(192, 0, 0), ColorUtility.ColorFromRGB(32, 0, 0), 0, 0, Width, Height);

      for (Int32 x = 0; x < 4; x++) {
         Bitmap b = new Bitmap(Width / 4, Height / 4);
         b.StretchImage(0, 0, app.Snowflake, b.Width, b.Height, (UInt16)((x + 1) * 50));
         Image image = new Image(b);
         panel.Children.Add(image);
      }
   }

   // This class shows how to build your own Panel
   private sealed class DiagonalPanel : Panel {
      public DiagonalPanel() {
      }

      protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) {
         // Called to calculate the width/height desired
         desiredWidth = 0;
         desiredHeight = 0;
         foreach (UIElement child in Children) {
            if (child.Visibility != Visibility.Collapsed) {
               child.Measure(Int32.MaxValue, Int32.MaxValue);
               Int32 childWidth, childHeight;
               child.GetDesiredSize(out childWidth, out childHeight);
               desiredWidth += childWidth;
               desiredHeight += childHeight;
            }
         }
      }

      protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) {
         Int32 x = 0, y = 0;
         foreach (UIElement child in Children) {
            if (child.Visibility != Visibility.Collapsed) {
               Int32 childWidth, childHeight;
               child.GetDesiredSize(out childWidth, out childHeight);
               child.Arrange(x, y, childWidth, childHeight);
               x += childWidth;
               y += childHeight;
            }
         }
      }
   }
}


//////////////////////////////////////////////////////////////////////////////

后记:此外在会上还遇到了我的偶像马宁、马琪、张欣(还是张欣强,通过回答问题获得一个MF开放套件),如果他们不介意附上照片作个留念:-)
image.png

相关文章
|
22天前
|
机器学习/深度学习 人工智能 Cloud Native
洞察.NET 技术的前沿应用
【7月更文挑战第4天】**洞察.NET技术前沿:.NET Core跨平台崛起,云原生与AI应用深化。ML.NET、TensorFlow.NET助力机器学习,Xamarin与MAUI统一跨平台UI。Azure云服务支持下,.NET引领软件开发新趋势。**
29 5
|
22天前
|
人工智能 物联网 开发工具
.NET技术:多元语言、丰富库与跨平台能力引领软件开发新纪元。
`【7月更文挑战第4天】.NET技术:多元语言、丰富库与跨平台能力引领软件开发新纪元。从企业应用、云服务到游戏开发,其角色日益凸显。随着微软的持续创新与社区合作,未来.NET将在物联网、AI等领域拓宽应用,开发者应把握趋势,共创未来。`
20 0
|
3天前
|
开发框架 搜索推荐 前端开发
【.NET全栈】ASP.NET开发Web应用——Web部件技术
【.NET全栈】ASP.NET开发Web应用——Web部件技术
|
22天前
|
人工智能 开发框架 Devops
.NET技术概览:** 本文探讨了.NET的核心特性,包括多语言支持、Common Language Runtime、丰富的类库和跨平台能力,强调其在企业级、Web、移动及游戏开发中的应用。
【7月更文挑战第4天】.NET技术概览:** 本文探讨了.NET的核心特性,包括多语言支持、Common Language Runtime、丰富的类库和跨平台能力,强调其在企业级、Web、移动及游戏开发中的应用。此外,讨论了.NET如何通过性能优化、DevOps集成、AI与ML支持以及开源策略应对未来挑战,为开发者提供强大工具,共创软件开发新篇章。
21 3
|
22天前
|
人工智能 前端开发 开发工具
**.NET技术概览:** 本文探讨.NET的核心优势
【7月更文挑战第4天】**.NET技术概览:** 本文探讨了.NET的核心优势,如统一开发平台、Visual Studio的强大工具、跨平台能力及丰富的类库。它在现代应用中的创新应用包括企业级、Web、移动、云服务和游戏开发。同时,面对性能优化、容器化、AI集成等挑战,.NET正寻求未来机遇,通过开源社区持续发展。开发者应抓住这些趋势,利用.NET推动软件创新。
26 1
|
22天前
|
人工智能 前端开发 Devops
NET技术在现代开发中的影响力日益增强,本文聚焦其核心价值,如多语言支持、强大的Visual Studio工具、丰富的类库和跨平台能力。
【7月更文挑战第4天】**.NET技术在现代开发中的影响力日益增强,本文聚焦其核心价值,如多语言支持、强大的Visual Studio工具、丰富的类库和跨平台能力。实际应用涵盖企业系统、Web、移动和游戏开发,以及云服务。面对性能挑战、容器化、AI集成及跨平台竞争,.NET持续创新,开发者应关注技术趋势,提升技能,并参与社区,共同推进技术发展。**
18 1
|
22天前
|
机器学习/深度学习 人工智能 开发者
.NET 技术:为开发带来新机遇
【7月更文挑战第4天】**.NET技术开启软件开发新篇章,通过跨平台革命(.NET Core, Xamarin, .NET MAUI)、云服务与微服务(Azure, DevOps, Docker)及AI集成(ML.NET, 认知服务, TensorFlow)为开发者创造新机遇。开源社区的繁荣与性能提升使.NET更具竞争力,推动智能应用的创新与发展。开发者需紧跟潮流,利用这些工具和框架构建高效、创新的解决方案。**
19 1
|
22天前
|
人工智能 前端开发 开发工具
.NET技术探析:优势、创新应用及挑战。
【7月更文挑战第4天】**.NET技术探析:优势、创新应用及挑战。本文分三部分展开,阐述了.NET作为统一多语言开发平台的核心优势,如强大的Visual Studio工具、跨平台能力与丰富的类库;探讨了其在企业级、Web、移动及游戏开发中的创新角色;并指出面临性能优化、容器化、AI集成等挑战及未来开源社区驱动的发展机遇。通过理解与应对,开发者可借助.NET推动软件开发进步。**
21 0
|
29天前
|
XML 机器学习/深度学习 移动开发
技术笔记:log4net使用详解
技术笔记:log4net使用详解
23 0
|
29天前
|
存储 安全 C#
技术心得记录:强命名的延迟与关联在.net程序集保护中的作用及其逆向方法
技术心得记录:强命名的延迟与关联在.net程序集保护中的作用及其逆向方法