public
Last active

Command Example

  • Download Gist
using_commands.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.