Created
August 24, 2009 13:25
-
-
Save Ball/173878 to your computer and use it in GitHub Desktop.
Command Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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