Quick Silverlight (and WPF) tip: How to write program without XAML

23 בדצמבר 2008

אין תגובות

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/quick-silverlight-and-wpf-tip-how-to-write-program-without-xaml/]


From the moment, 10K MIX09 contest was launched, I got more, then 20 people, asking the same question: Is it possible to have Silverlight program up and running without XAML at all?

image

The answer is “YES, IT IS”. Here is how:

All you need for run WPF or Silverlight application is

  1. Class inherited from System.Windows.Application
  2. Class inherited from System.Windows.Controls.UserControl

So, Let’s create new WPF or Silverlight application and delete all files from the project directory. Then add one file, named App.cs (or Foo.cs or Whatever.cs – the length of the file name is not included :) ) and write there :

using System.Windows.Controls;
using System.Windows;

public class App : Application {public App() {this.Startup += (s, e) => { this.RootVisual = Foo.M; };}} 
class Foo: UserControl {static Foo _b = new Foo();public static Board M { get { return _b; } }

We done. F5, be happy. You just wrote first officially smallest Silverlight functional application. Good luck with Mix09 contest.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים