Skip to content

Instantly share code, notes, and snippets.

@Ball
Created August 14, 2009 12:58
Show Gist options
  • Save Ball/167804 to your computer and use it in GitHub Desktop.
Save Ball/167804 to your computer and use it in GitHub Desktop.
Some extentions to WPF classes to make WPF easier in Ironruby
require 'PresentationCore'
require 'PresentationFramework'
include System::Windows
include System::Windows::Controls
class FrameworkElement
def self.create_new( hash )
elem = new()
hash.each_pair do |key, value|
elem.send( "#{key}=".to_sym, value)
end
elem
end
end
class Panel
def <<(new_children)
if new_children.respond_to? :each
new_children.each do |child|
self.children.add child
end
else
self.children.add new_children
end
end
end
window = Window.create_new(:title => "Lef' Frontal Lobe",
:size_to_content => SizeToContent.height,
:width => 450 )
window.content = stack = StackPanel.create_new(:margin => Thickness.new(15))
search_ctl = StackPanel.create_new( :orientation => Orientation.horizontal )
search_box = TextBox.create_new( :width => 390 )
search_button = Button.create_new(:content => "Go")
search_ctl << [search_box, search_button]
results_label = Label.create_new(:font_size => 24,
:content => "Results",
:horizontal_alignment => HorizontalAlignment.center,
:margin => Thickness.new(5))
results_list = ListBox.new()
stack << [search_ctl, results_label, results_list]
search_button.click do |sender, event|
results_list.items.clear
results_list.items.add search_box.text
end
Application.new().run( window )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment