Create a gist now

Instantly share code, notes, and snippets.

XamlTools
require 'rubygems'
require 'builder'
require 'PresentationCore'
require 'PresentationFramework'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeytoken=b77a5c561934e089'
module XamlTools
include System::Windows
StringReader = System::IO::StringReader;
XamlReader = System::Windows::Markup::XamlReader
XmlReader = System::Xml::XmlReader;
class System::Windows::Window
def [](arg)
self.find_name(arg.to_s)
end
end
class Xaml
def self.add_xaml_ns(hash)
if not hash.key? "xmlns:x"
hash["xmlns:x"] = "http://schemas.microsoft.com/winfx/2006/xaml"
end
end
def self.add_presentation_ns(hash)
if not hash.key? :xmlns
hash[:xmlns] = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
end
end
def self.create(hash, &block)
add_presentation_ns hash
add_xaml_ns hash
xaml = Builder::XmlMarkup.new(:indent => 2)
yield(xaml)
XamlReader.load(XmlReader.create(StringReader.new(xaml.target!.to_clr_string)))
end
def self.page(hash, &block)
create(hash) do |xaml|
xaml.Page(hash, &block)
end
end
def self.user_control(hash, &block)
create(hash) do |xaml|
xaml.UserControl(hash, &block)
end
end
def self.window(hash, &block)
create(hash) do |xaml|
xaml.Window(hash, &block)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment