Hi guys,
I need your help - PLEASE !
I am currently trying to add a RelayCommand class to my 'Stock' app for Cologne.
The C# class came from an article in C#Corner and I have the code working in one of my earlier apps. Now I want to translate it all to X#, and the central class is the 'RelayCommand' class. I am not using a MVVM framework doing things this way.
I have done some of the translating so here is my imperfect attempt (so far) :-
And here is the image of the C# code for comparison :-
And I suppose you guys want the text code too :-
====================================================================
public class RelayCommand implements ICommand
//----- from C# Corner -----
private execute as Action<object>
private canExecute as Func<object, Boolean>
//----- events -----
public event CanExecuteChanged as EventHandler
add ( CommandManager.RequerySuggested += value )
remove ( CommandManager.RequerySuggested -= value )
return
//--- constructor ---
constructor(execute as Action<object>, canExecute := null as Func<object, Boolean> )
self:execute := execute
self:canExecute := canExecute
return
//--- methods ---
public method CanExecute(parameter as object) as Boolean
return ( self:canExecute == null || self:canExecute(parameter) )
public method Execute(parameter as object) as void
self:execute(parameter)
return
end class
======================================================================
Any suggestions welcomed - TIA.
Regards,
Phil.
Wales, UK.
HELP - with X# syntax - Relay Command ...
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP - with X# syntax - Relay Command ...
Phil,
Looks ok with one Exception: Func is a keyword in our language (that is why it is colored Blue). Change that to @@Func and I think it will work.
There are a few hardcoded abbreviations in our language (because they are also in Vulcan):
FUNC
PROC
LONG
SHORT
Robert
Looks ok with one Exception: Func is a keyword in our language (that is why it is colored Blue). Change that to @@Func and I think it will work.
There are a few hardcoded abbreviations in our language (because they are also in Vulcan):
FUNC
PROC
LONG
SHORT
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP - with X# syntax - Relay Command ...
Thanks Robert,
I will follow up what you suggest - BUT - to let you all know that I did try to help myself, I attach an image of the Reflector 9 conversion using Fabrice's plug-in for Vulcan. This will help to cross-check the rest of the stuff I tried out in X#. @@ is still missing however.
Does anyone know why I seem NOT to be able to copy the text from Reflector any more. I am sure I remember in the past copying / pasting lots, and lots of similar code. I have a fully paid up licenced version of Reflector 9. Should it work ?
Oh! and before I go, let me say that when I get the 'RelayCommand' stuff working I will make all bits of the stuff available to you - a small app perhaps. This allows us to do some basic (and important) MVVM stuff to keep event handlers out of the code behind the XWP / XAML form - will keep Frank happy as it good practise for testing ;-0) And the code does not get complicated.
Bed now, and try this stuff in the morning.
Weather getting colder and whiter in the UK.
Cheers,
Phil.
I will follow up what you suggest - BUT - to let you all know that I did try to help myself, I attach an image of the Reflector 9 conversion using Fabrice's plug-in for Vulcan. This will help to cross-check the rest of the stuff I tried out in X#. @@ is still missing however.
Does anyone know why I seem NOT to be able to copy the text from Reflector any more. I am sure I remember in the past copying / pasting lots, and lots of similar code. I have a fully paid up licenced version of Reflector 9. Should it work ?
Oh! and before I go, let me say that when I get the 'RelayCommand' stuff working I will make all bits of the stuff available to you - a small app perhaps. This allows us to do some basic (and important) MVVM stuff to keep event handlers out of the code behind the XWP / XAML form - will keep Frank happy as it good practise for testing ;-0) And the code does not get complicated.
Bed now, and try this stuff in the morning.
Weather getting colder and whiter in the UK.
Cheers,
Phil.
HELP - with X# syntax - Relay Command ...
Phil,
I can spot also another thing, the event in X# must be defined in x# syntax:
EVENT myEvent AS EventHandler
ADD
CommandManager.RequerySuggested += VALUE
END ADD
REMOVE
CommandManager.RequerySuggested += VALUE
END REMOVE
END EVENT
Chris
I can spot also another thing, the event in X# must be defined in x# syntax:
EVENT myEvent AS EventHandler
ADD
CommandManager.RequerySuggested += VALUE
END ADD
REMOVE
CommandManager.RequerySuggested += VALUE
END REMOVE
END EVENT
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
HELP - with X# syntax - Relay Command ...
Hi Phil,
the EVENT ADD REMOVE functionality is another sign how the X# team works: Robert added it shortly after I had requested it because I needed it to move my C# RelayCommand class to X#.
If you look at my X# MVVM sample in XIDE, you'll find this class there.
Wolfgang
the EVENT ADD REMOVE functionality is another sign how the X# team works: Robert added it shortly after I had requested it because I needed it to move my C# RelayCommand class to X#.
If you look at my X# MVVM sample in XIDE, you'll find this class there.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP - with X# syntax - Relay Command ...
Thanks Chris, and all you other guys too ;-0)
I have implemented your ideas and suggestions as well as a couple of my own. I have attached the version which now compiles fine - testing will come a little later today.
I like the Add / Remove syntax.
One issue which hit me was caused by me translating C# code where the code designer had used just the different case sensitivity of a member name to distinguish it from another. (Not a good idea in my books.) Hence the changes you may see to clarify things, me using '_execute' and also 'in_execute' with the method name 'Execute' staying as it is.
This suggests to me that we will need to be VERY careful in what code we translate and use from C# examples, I have not been hit by this before now, I think!?
Has anyone got an answer for me on the problem / issue of copying text from 'Reflector 9' - in my Windows 10 set-up I can't highlight the code for pasting.
TIA, and thanks once again for all the tips ;-0)
Cheers,
Phil.
I have implemented your ideas and suggestions as well as a couple of my own. I have attached the version which now compiles fine - testing will come a little later today.
I like the Add / Remove syntax.
One issue which hit me was caused by me translating C# code where the code designer had used just the different case sensitivity of a member name to distinguish it from another. (Not a good idea in my books.) Hence the changes you may see to clarify things, me using '_execute' and also 'in_execute' with the method name 'Execute' staying as it is.
This suggests to me that we will need to be VERY careful in what code we translate and use from C# examples, I have not been hit by this before now, I think!?
Has anyone got an answer for me on the problem / issue of copying text from 'Reflector 9' - in my Windows 10 set-up I can't highlight the code for pasting.
TIA, and thanks once again for all the tips ;-0)
Cheers,
Phil.
HELP - with X# syntax - Relay Command ...
Hi Phil,
you have an error in your EVENT REMOVE code. Instead of
you should write
Wolfgang
you have an error in your EVENT REMOVE code. Instead of
Code: Select all
public event CanExecuteChanged as EventHandler
add
CommandManager.RequerySuggested += VALUE
end add
remove
CommandManager.RequerySuggested += VALUE
end remove
end event
Code: Select all
public event CanExecuteChanged as EventHandler
add
CommandManager.RequerySuggested += VALUE
end add
remove
CommandManager.RequerySuggested -= VALUE
end remove
end event
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP - with X# syntax - Relay Command ...
Thanks Wolfgang,
I think I just copied and pasted it from Chris's post - blame someone else ;-0)
Changes now made, and I have the whole code working (even with the error).
So far just a single Button for click response - this should do my whole Cologne demo app.
I have included a few images of working code in case anyone else is interested.
Thanks once again to all who helped me 'get there' !
Cheers,
Phil.
I think I just copied and pasted it from Chris's post - blame someone else ;-0)
Changes now made, and I have the whole code working (even with the error).
So far just a single Button for click response - this should do my whole Cologne demo app.
I have included a few images of working code in case anyone else is interested.
Thanks once again to all who helped me 'get there' !
Cheers,
Phil.
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
HELP - with X# syntax - Relay Command ...
Sorry guys,
Although a simple bit of code, it is needed to complete the picture - fits with the four I sent earlier.
Now all my code is in the VM (view model) and not in the code behind of the View itself. Keep you happy Frank !
Regards,
Phil.
Although a simple bit of code, it is needed to complete the picture - fits with the four I sent earlier.
Now all my code is in the VM (view model) and not in the code behind of the View itself. Keep you happy Frank !
Regards,
Phil.
HELP - with X# syntax - Relay Command ...
Hi Phil,
sorry for blaming the wrong person!
This is only needed if you need to activate/deactivate buttons (again a piece of code from my sample):
Wolfgang
sorry for blaming the wrong person!
This is only needed if you need to activate/deactivate buttons (again a piece of code from my sample):
Code: Select all
self:OkButton := RelayCommand{ SaveData, CanSaveData }
method SaveData( oObject as object ) as void
Application.Current:MainWindow:Close()
return
virtual method CanSaveData( oObject as object ) as logic
local lReturn as logic
if String.IsNullOrEmpty( _oServer:Value1 ) .or. String.IsNullOrEmpty( _oServer:Value2 )
lReturn := false
else
lReturn := true
endif
return lReturn
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it