Professional Programmer Notes

or just call this my soapbox

Posts Tagged ‘python

WPF’ing around with Boo and external xaml files

leave a comment »

Here is a snippet of Boo code (formatted with Python syntax highlighter) that will load a xaml file into a WPF Window:

import System
import System.Windows from PresentationFramework
import System.Windows.Markup from PresentationFramework
import System.IO

class XamlWindow(Window):
	def constructor(name):
		load_xaml(name)

	def load_xaml(name):
		xaml_file = File.OpenRead(Path.GetFullPath(name))
		self.Content = XamlReader.Load(xaml_file)

Application().Run(XamlWindow("mainui.xaml"))</pre>

See http://devpinoy.org/blogs/smash/archive/2006/10/04/XAMl-meets-Boo.aspx for reference.

Alternatively, here is the equivalent IronPython code:

import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")

from System.Windows import Window, Application
from System.Windows.Markup import XamlReader
from System.IO import File, Path

class XamlWindow(Window):
	def __init__(self, name):
		self.load_xaml(name)

	def load_xaml(self, name):
		xaml_file = File.OpenRead(Path.GetFullPath(name))
		self.Content = XamlReader.Load(xaml_file)

Application().Run(XamlWindow("mainui.xaml"))

Lastly, here is an example xaml file

<StackPanel
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Label Content="Hello World" />
    <Button Content="Clickable" />
</StackPanel>
Note: There is no UserControl or Window element and the namespaces are defined on the root container, the StackPanel.
Results:
screenshot of very simple wpf app

Written by curtismitchell

May 22, 2011 at 5:39 pm

Posted in .net

Tagged with , , , , ,

Gestalt = Low-Lying Awesome

leave a comment »

Microsoft appears to be betting big on Silverlight.  When the Silverlight 1.0 bits were released in 2007, my initial thoughts were, “Yay, Flash for .NET developers.”  As Microsoft pushed forward with version 2, version 3, and now version 4 of Silverlight, those sarcastic thoughts have subsided to make way for more genuine curiosity.  How did that happen?

Well, for starters, Microsoft delivered real features.  Initially, Silverlight demos were all about media (music and video).  In addition, Microsoft touted the interopability between dynamic languages like vbx, c#, python, ruby, and javascript.  Then, that interopability was sidelined and Silverlight applications started to emerge.  Which was interesting.  In fact, Silverlight 2 had enough features to stir up debates in the enterprise over which RIA technology was best suited for enterprise applications: Flash 8 with Flex or Silverlight 2.   Then, Microsoft played their wildcard.  They made Silverlight play nicely with … ugh … Mac OSX.  Out-of-browser Silverlight applications made me raise my eyebrows for a technology that I had quickly written off as a “fad”.

That might still be the case.  I won’t make a claim either way.  But, Silverlight and RIA are spaces where Microsoft continue to innovate.  Gestalt is a very good example of that last statement.  Gestalt is built atop a foundation consisting of XAML, Silverlight, and dynamic languages.  It enables web developers to script their way to rich internet applications in a way that both Flash and Silverlight seemingly missed. 

With that said, it is difficult to pinpoint exactly what value Gestalt adds, but you feel it when you’re molding some python, ruby, or javascript hackery into a magical Silverlight-powered application that just works.

The technology appears to still be more of a proof-of-concept than a supported product.  But, it makes a strong case for embracing XAML and Silverlight. 

Checkout the website and the samples at http://visitmix.com/labs/gestalt/.

Written by curtismitchell

February 11, 2010 at 9:59 pm

Posted in .net, CSharp, Javascript, web

Tagged with , , , , ,