Skip to content

Instantly share code, notes, and snippets.

@Ball
Created August 24, 2009 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ball/173878 to your computer and use it in GitHub Desktop.
Save Ball/173878 to your computer and use it in GitHub Desktop.
Command Example
require 'xamltools.rb'
class MyCommand
include System::Windows::Input::ICommand
def add_CanExecuteChanged(h)
@change_handlers << h
end
def remove_CanExecuteChanged(h)
@change_handlers.remove(h)
end
def can_execute(args)
@can_execute
end
def execute(arg)
puts "I'm being commanded"
@can_execute = false
@change_handlers.each{ |h| h.Invoke(self, System::EventArgs.new) }
end
def initialize
@change_handlers = []
@can_execute = true
end
end
class ViewModel
attr :my_command, true
def initialize
@my_command = MyCommand.new
end
end
view = XamlTools::Xaml.window( :Width => 450, :SizeToContent => :Height) do |w|
w.Button( :Content => "Click Me!", :Command => "{Binding Path=my_command}")
end
view.data_context = ViewModel.new
System::Windows::Application.new.run(view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment