Skip to content

@Ball /using_commands.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.