How do I...Set a Click Event on a Button
7 posts
• Page 1 of 1
How do I...Set a Click Event on a Button
In APL:
In XAML:
where function foo has the form:
To add a second handler (cumulatively):
⎕USING←'' 'System.Windows,WPF/PresentationFramework.DLL'
⎕USING,←⊂'System.Windows.Controls'
btn←⎕NEW Button
btn #.WPF.Event.Add 'Click' 'foo'
foo ⍝ Add lists all handlers as its result
In XAML:
- Code: Select all
xmlns:apl="clr-namespace:MJHSoftware;assembly=MJHSoftware.APLExtension"
<Button Click="{apl:Event foo}" />
where function foo has the form:
- Code: Select all
∇ foo(Sender e)
[1] e.Handled←1 ⍝ Marks the event as "handled"
∇
To add a second handler (cumulatively):
btn #.WPF.Event.Add 'Click' 'goo'
foo goo ⍝ Add lists all handlers as its result
-
Fiona|Dyalog - Posts: 74
- Joined: Mon Apr 22, 2013 12:59 pm
Re: How do I...Set a Click Event on a Button
Where can I find the appropriate MJHSoftware.APLExtension assembly to make the XAML example work?
(It's the little things that make the difference :-)
-
norbertjurkiewicz84 - Posts: 62
- Joined: Mon Nov 01, 2010 7:26 pm
Re: How do I...Set a Click Event on a Button
Can anyone point me to directions for setting commands and events in XAML? The example below shows using another assembly. Is that something that's available and ready for public release?
(It's the little things that make the difference :-)
-
norbertjurkiewicz84 - Posts: 62
- Joined: Mon Nov 01, 2010 7:26 pm
Re: How do I...Set a Click Event on a Button
Hi Norbert,
The mjh software extension might not be needed anymore for this.
Please have a look at the supplied wpfintro workspace in the ws subdirectory of your 14.0 install and "Chapter 4: Windows Presentation Foundation" of the Dyalog .NET Interface Guide.
Regards,
Vince
The mjh software extension might not be needed anymore for this.
Please have a look at the supplied wpfintro workspace in the ws subdirectory of your 14.0 install and "Chapter 4: Windows Presentation Foundation" of the Dyalog .NET Interface Guide.
Regards,
Vince
- Vince|Dyalog
- Posts: 432
- Joined: Wed Oct 01, 2008 9:39 am
Re: How do I...Set a Click Event on a Button
Hi Vince,
Both the documentation and wpfintro show how to use workspace functions to find individual objects and assign callbacks in code. I'd like to assign the callbacks and commands directly in XAML.
I looked through the wpfintro code and didn't see any examples of callback assignment in XAML. Please correct me if I glossed over it by mistake.
.NET Ch. 4 and wpfintro style.
vs example in this thread.
I'd like to do the latter.
Norbert.
Both the documentation and wpfintro show how to use workspace functions to find individual objects and assign callbacks in code. I'd like to assign the callbacks and commands directly in XAML.
I looked through the wpfintro code and didn't see any examples of callback assignment in XAML. Please correct me if I glossed over it by mistake.
.NET Ch. 4 and wpfintro style.
- Code: Select all
[13] mnuFahrenheit←win.FindName⊂'mnuFahrenheit'
[14] mnuFahrenheit.onClick←'SET_F'
[15] mnuCentigrade←win.FindName⊂'mnuCentigrade'
[16] mnuCentigrade.onClick←'SET_C'
[17] (btnF2C←win.FindName⊂'btnF2C').onClick←'f2c'
[18] (btnC2F←win.FindName⊂'btnC2F').onClick←'c2f'
[19] (btnQuit←win.FindName⊂'btnQuit').onClick←'Quit'
[20] (scrTemp←win.FindName⊂'scrTemp').onScroll←'F2C'
vs example in this thread.
- Code: Select all
<Button Click="{apl:Event foo}" />
I'd like to do the latter.
Norbert.
(It's the little things that make the difference :-)
-
norbertjurkiewicz84 - Posts: 62
- Joined: Mon Nov 01, 2010 7:26 pm
Re: How do I...Set a Click Event on a Button
The issue - as I understand it, and someone will surely be along soon to correct me - is that XAML doesn't know about APL, and the code that gets called when you load XAML into your APL session can't figure out what you're talking about.
There are clever ways to resolve this.
There are also really dumb ways to resolve this.
As an accredited simpleton, I do things the dumb way...
First step is to establish a convention that you'll use in your XAML - what I do is to stick a ∇ in front of the callback name, so the XAML contains something like this...
Click="∇#.HTMLTOOLS.VIEW.View"
Then my application has stuff like this...
#.wdwDogMetal names callbacks←#.UTIL.XAML.LoadXAML(#.GLOBALS.homefolder,'XAML/htmltools.xaml')(⊂'Ribbon')
#.wdwDogMetal←names #.UTIL.WPFTOOLS.SetObjects #.wdwDogMetal
#.wdwDogMetal←callbacks #.UTIL.WPFTOOLS.SetCallbacks #.wdwDogMetal
where <LoadXAML> <SetObjects> and <SetCallbacks> are utility functions what I wrote (and or copied from the better-informed). I won't show them because they do a bit more than the bare bones - but basically <LoadXAML> strips out the bits that "real XAML" can't understand and passes the essential on, while spewing out lists of names and callbacks - your APL needs the names anyway, so <SetObjects> sorts all that out, while <SetCallbacks> does what it says on the can.
The point being that - having invested the time once to create these ustilities - I don't have to think about how they're doing whatever they do, I just use them in my thought-free world.
As I say - there are cleverer ways to go about this. But as my old auntie used to say, "great thing about APL is that there are so many ways to skin a cat - and it doesn't cost you a lot to try several of them out".
There are clever ways to resolve this.
There are also really dumb ways to resolve this.
As an accredited simpleton, I do things the dumb way...
First step is to establish a convention that you'll use in your XAML - what I do is to stick a ∇ in front of the callback name, so the XAML contains something like this...
Click="∇#.HTMLTOOLS.VIEW.View"
Then my application has stuff like this...
#.wdwDogMetal names callbacks←#.UTIL.XAML.LoadXAML(#.GLOBALS.homefolder,'XAML/htmltools.xaml')(⊂'Ribbon')
#.wdwDogMetal←names #.UTIL.WPFTOOLS.SetObjects #.wdwDogMetal
#.wdwDogMetal←callbacks #.UTIL.WPFTOOLS.SetCallbacks #.wdwDogMetal
where <LoadXAML> <SetObjects> and <SetCallbacks> are utility functions what I wrote (and or copied from the better-informed). I won't show them because they do a bit more than the bare bones - but basically <LoadXAML> strips out the bits that "real XAML" can't understand and passes the essential on, while spewing out lists of names and callbacks - your APL needs the names anyway, so <SetObjects> sorts all that out, while <SetCallbacks> does what it says on the can.
The point being that - having invested the time once to create these ustilities - I don't have to think about how they're doing whatever they do, I just use them in my thought-free world.
As I say - there are cleverer ways to go about this. But as my old auntie used to say, "great thing about APL is that there are so many ways to skin a cat - and it doesn't cost you a lot to try several of them out".
Visit http://apl.dickbowman.com to read more from Dick Bowman
-
Dick Bowman - Posts: 235
- Joined: Thu Jun 18, 2009 4:55 pm
Re: How do I...Set a Click Event on a Button
Hello Norbert, find attached a copy of the function we use to 'Fix' our Xaml (GetObjectFromXaml). In our case the callback function need to begin with the underscore character '_' because it is compatible with Visual Studio (VS does not accept a del '∇' character as first character, but will accept an underscore '_'). Also in order to fix a callback the control need to be named. For example this will work in Xaml:
<Button x:Name="MyButton" Click="_buttonClick"/>
The function 'GetObjectFromXaml' will only fix the names and events of the controls. If you need to fix only the names, the function 'FixSimpleXaml' is shorter.
Pierre Gilbert
<Button x:Name="MyButton" Click="_buttonClick"/>
The function 'GetObjectFromXaml' will only fix the names and events of the controls. If you need to fix only the names, the function 'FixSimpleXaml' is shorter.
Pierre Gilbert
-
PGilbert - Posts: 440
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group