Question

I'm just getting started with Oxygene.

I'm trying to make a litlle WPF project with a MVVM pattern. So far it's working but i can't find a way to implement commands in oxygene.

Does anyone know if this can be done and if so how?

Était-ce utile?

La solution

First you need to create a static class in the same project as the form is. like this:

Command = public static class 
  public
    SomeCommand: RoutedCommand := new RoutedCommand();
end;

Then you need to create a XAML name space alias (in the XAML of your form):

xmlns:Local="clr-namespace:YourProjectNameSpace" 

Suppose you have a button on the form and you want to hook it up to the command:

 <Button Content="Some Button" Command="{x:Static Local:Command.SomeCommand}" />

The next step is to setup what the command should be doing... In my case I just hooked up a lambda expression but you can use the MVVM pattern to delegate this behaviour to somewhere else.

I did this in the load of the form:

self.CommandBindings.Add(new CommandBinding(Command.SomeCommand, (ss,ee) -> 
begin
  //Do Stuff
  //Do some more stuff
end));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top