.Net (Compact) Framework
Outline
Introduce .Net Compact Framework Features Controls Issues in UI Design Sample Application
Product Framework
Bring device developers to .NET
.NET Knowledge Transfer
Consistent API behavior Visual Studio best tool C#, Visual Basic
Rich Class Libraries
Developer productivity Ease of use Robustness
IT Interop
Networking XML & Databases Durable messaging
Windows CE
Compatibility with native security Full integration with native setup Native code interop
Bring .NET developers to devices
.NET Compact Framework
Visual Studio
Rich class libraries to make your life easy!
GUI: Forms GUI: Drawing (2D & 3D) Collections IO, Networking, Crypto Native interop Web services Data & Xml Globalization
Execution Engine provides typesafe runtime for managed code
Type system Loader JIT Compiler Garbage collector Debugger
Low level operating system-specific functionality
Threads Memory File I/O Networking Localization
.NET Framework And .NET Compact Framework
Both
Modern, managed runtime environments Greatly enhance developer productivity Provide both C# and VB.NET languages* Major releases in Visual Studio
Full .NET Framework
Extremely rich, scalable, secure, powerful
.NET Compact Framework
Preserves essence of full .NET Framework Optimized for small size, portability
* More languages available from 3rd parties and on full .NET Framework
Smaller Yet Compatible
28% of the surface area in 8% of the size Omitted
Server functionality ASP.NET Remoting Code Access Security Reflection Emit (scripting) Individual properties, methods, events – classes factored at member level Managed C++, J#
Ground-up rewrite Snapshot & Modify
86% scope of Full .NET Framework
System.Text.Regex System.Xml
Copy
Execution Engine JIT, GC, Loader, assembly cache
System.Threading System.IO
Microsoft.Win32. Registry System.Cryptography
System.Collections System.Generic. Collections
Microsoft.DirectX. Direct3DMobile
Windows.Forms System.Drawing System.Web.Services
System.Resources System.IO.Ports System.Net System.String
System.Data System.Messaging Microsoft.VisualBasic 91% scope of Full .NET Framework System.Globalization System.Text
Compatibility
Applications written using prior versions of the .NET Compact Framework just work on new versions
Goal is full backward compatibility We support SxS as a fallback, but we aim for this to be unneeded
New versions of .NET Compact Framework run on previous versions of Windows CE and Windows Mobile
Windows Mobile support policy: n-2 Windows CE support policy: n-1
Supported Devices
V1
PocketPC 2000 PocletPC 2002 PocketPC 2003, SE SmartPhone 2003 WinCE 4.1 WinCE 4.2 WinCE 5.0
V2
Pocket PC 2003 SE Pocket PC 2005 Smart Phone 2005 WinCE 5.0
Generics
Classes and methods that work similarly on values of different types
Variables are specific types, not objects No casting required
class Stack { private T[] store; private int size; public Stack() { store = new T[10]; size = 0; } public void Push(T x) { // push code goes here } public T Pop() { return store[--size]; } } void Add(Stack s) { int x = s.Pop(); int y = s.Pop(); s.Push(x+y); }
Benefits
Re-use common code Find bugs at compile time
More New C# Language Features
Anonymous Methods – Code blocks encapsulated in a delegate
Before
// in constructor button.Click += new EventHandler(ProcessClick); // separate method void ProcessClick(object sender,EventArgs e) { // increment a counter or other action }
After
// in constructor button.Click += new EventHandler(sender,args) { // increment a counter or other action };
Partial Types – Split definitions for types and class members across multiple files
C# compiler combines all definitions to make a single class
Foo-Part1.cs
public partial class Foo { public void CodeGenFunc() { // emitted by tool } }
Foo-Part2.cs
public partial class Foo { public void UserFunc() { // user code } }
VB.NET
Easiest and most productive way to develop .NET applications .NET Compact Framework continues to support VB.NET New support for a subset of VB.NET My namespace
My.Resources My.WebServices My.Forms
Rich Controls
Pocket PC Smartphone
DateTimePicker
DocumentList
Notification Bubble
UserControl
Easily build and reuse your own custom controls Well integrated into design time experience
MonthCalendar
LinkLabel
More Controls
MonthCalendar LinkLabel Help WebBrowser DataContainer New on Smartphone
Datagrid Textbox IME switching Enable multiple menu items on left softkey
Forms And Drawing
More Keyboard Support
Events Form.KeyPreview Tabs
Integrated keyboards
Clipboard support Drawing
Bitmaps (including save as…) Rotatable fonts Custom Pens
HP 4300
Rotated text using LOGFONT
Control.Handle – retrieve window handle Lots of additional properties, methods, events
Displays And Layout
Support for new and future devices
Orientation Support
ChangeOrientation method Docking and Anchoring AutoScroll property – forms, panels Suspend/Resume Layout methods
Resolution Support
Automatic scaling Graphics DpiX/DpiY
Managed D3D Mobile
Included in WinCE 5.0 and future versions of Windows Mobile
Native API is DX8 inspired Managed APIs are DX9 inspired
Features
Complete access to the underlying native D3DM API Fixed point support (Vertex Data, Matrices, Lights, and Materials) Sprite Font Mesh TextureLoader Tutorials and Samples
Related session: CLI317 Game Development Using Managed Direct3D Mobile with the .NET Compact Framework
Base Class Libs, Networking, Web Services
Serial Port
Four ports Supported in the emulator
IPv6 Generic-based collections classes
Leverage the power of new Generics language feature
Web services
Faster XmlSerializer Support for SOAP 1.2
Data And Xml Class Libraries
System.Data
Powerful data designer tools integrated into Visual Studio 2005 SQL Mobile 2005
Available with Visual Studio 2005 (or as download) Smartphone support! SqlCeResultSet (Updateable scrollable cursor) Storage Engine - Multi-User and Multi-Connection support
Many ADO.NET features added to track full .NET Framework
System.Xml
Serialization of live objects like application settings Schemas
Validate XML against schema constraints Generate schemas on the fly programmatically
XPath 1.0
System.Messaging (MSMQ)
Use for bi-directional communications over intermittent (unreliable) connections
.NET Compact Framework Application
Smart Device
Server Application
Operating System Message Queue
Data transferred when connection available. Device application does not need to be running.
Note: Can be used for Inter-Process communications also
Related session: CLI321 Using MSMQ to Build Reliable Mobile Applications
PIM And Telephony Classes
New in Windows Mobile 2005 Pocket Outlook Object Model (POOM) Appointments, contacts, tasks Phone – initiate calls Messaging – Email and SMS State & Notification
Related session: CLI318 New Managed Messaging, State, and Notification APIs in Windows Mobile
Windows Mobile User Interface Design
Windows Mobile UI Design
General concepts
Many familiar concepts
Mouse – stylus Keyboard – hardware buttons
What makes your app “mobile”? Keep in mind that user input is always a pain Keep UI simple
Think about 5 minute bursts of activity
Screen Orientation
What is it?
Landscape Portrait
Square
Screen Orientation
Design considerations
User can rotate at runtime Three main strategies
Resize content Relayout content Change content
Keep user experience intact
Screen Orientation
Application UI
Technique #1: Resize your content
Screen Orientation
Application UI
Technique #2: Relayout your content
Screen Orientation
Application UI
Technique #3: Change your content
Screen Orientation
Dialog strategies
Design for square screen Dynamic relayout
Screen Orientation
Dialogs
Strategy #1: Design for square screen
Screen Orientation
Dialogs
Strategy #2: Dynamic relayout
Screen Orientation
Native code
Swap dialog templates
DRA::RelayoutDialog
Relayout at runtime
WM_SIZE
Handle rotation
WM_SETTINGCHANGE DRA::GetDisplayMode
Screen Orientation
Managed code
Use control anchors
No code required with .NET CF 2.0!
Relayout at runtime
Form.OnResize
Handle rotation
Status.SystemState.DisplayRotation
Screen Orientation
Overall design issues
Don’t overcrowd your UI
Break information into multiple screens
Input panel issues in portrait mode
Watch out for edit controls
Screen Orientation
Input Panel “gotchas”
Screen Resolution
What is it?
96 DPI
131 DPI
Screen Resolution
Design considerations
Physical screen size stays the same
Pixel size gets smaller
Keep text BIG and readable Keep tap targets easy to hit Consistent user experience
Screen Resolution
Bitmaps and icons
Scaling up bitmaps at runtime looks clunky Scaling them down is even worse
Pixels drop out
Build bitmaps and icons for each DPI you support
Screen Resolution
Current support table
Pocket PC
96 DPI 131 DPI 192 DPI 480x640 240x320
Smartphone
176x220 240x320
Icons
Large: 32x32 Small: 16x16 Large: 44x44 Small: 22x22 Large: 64x64 Small: 32x32
Softkeys
What are they?
Smartphone
Pocket PC
Softkeys
What are they? (Part 2)
New for Pocket PC Well-tested and well-loved on phones Why? One-handed navigation Brings Pocket PC and Smartphone closer together
Softkeys
Design considerations
SK1 is the most likely user action
Non-destructive
SK2 can be an action or a menu Keep the menu small
Don’t duplicate SK1 in the menu No submenus if at all possible
Group similar actions together
Most common actions at the top
Softkeys
Converting legacy applications
No toolbar icons Softkey menus are typically smaller than Pocket PC 2003 menus No “New” menu Softkeys can be tapped on Pocket PC
Easy access when screen is rotated
Softkeys
Managed code
They just work!
System.Windows.Forms.MainMenu
Handling softkey commands
MenuItem.Click event handler
Device Input
Design considerations
Single taps, not double taps Minimize the number of taps or keys
Especially for common actions
Automatic menu accelerator keys Support common keyboard shortcuts as applicable
Cut, Copy, Paste Select All Bold, Italic, Underline
Device Input
Posture switching
Design for one-handed navigation Keyboard posture
Softkeys Edit controls Hardware buttons (including action/enter)
Stylus posture
Buttons Hyperlinks Tap-and-hold context menus
Sample Application
Forms
Snapshots Fax
ChooseContactDialog contactChooser = new ChooseContactDialog(); If (contactChooser.ShowDialog() == DialogResult.OK) { // Specify what happens // if the user selects a // contact }
contactChooser.RestrictContacts = “[CompanyName] = “\Contoso\””; contactChooser.RequiredProperties = new ContactProperty[] { ContactProperty.AllTextMessaging };
Gathering Properties from user only
Once you have a “SelectedContact,” call ShowDialog, after: Set ChoosePropertyOnly=True Returns SelectedProperty, (typeof PocketOutlook.Property); and SelectedPropertyValue, (string) Must have a valid SelectedContact first!
SelectPictureDialog picturepicker = new SelectPictureDialog();
If (picturepicker.ShowDialog() == DialogResult.OK) { // Specify what happens on a // successful return here }
CameraCaptureDialog camera = new CameraCaptureDialog(); If (camera.ShowDialog() == DialogResult.OK) { // Specify what happens on a // successful return here }