开发者

What is WCF RIA Commanding

开发者 https://www.devze.com 2023-02-17 03:20 出处:网络
What is WCF RIA Commanding? Is that even the proper name? I have a silverlight application in which I wan开发者_JAVA技巧t to use command binding to call methods on the webserver; however I\'m unsure

What is WCF RIA Commanding? Is that even the proper name?

I have a silverlight application in which I wan开发者_JAVA技巧t to use command binding to call methods on the webserver; however I'm unsure as to how to go about creating such a class and method so that it can be picked up by RIA and be used in the silverlight XAML; whiout any code behind.


a 'command' in the context of a Silverlight (or WPF) application is a class that implements the ICommand interface.

It is used to bind code in ViewModels to controls in Views.

Just about all the decent MVVM frameworks contain them (PRISM has DelegateCommand, MvvmLight has RelayCommand, etc) but it's not too hard to write your own...

Example usage:

in XAML:

<Button Command="{Binding GetCommand}" Content="Get" />

then in the ViewModel (bound to the View's DataContext)

public ICommand GetCommand
{
    get
    {
        if (_getCommand == null) _getCommand = new RelayCommand(GetHandler, CanGetPredicate);
        return _getCommand;
    }
}

private void GetHandler()
{
    // Do the work here - call into the server, or whatever.
}

private bool CanGetPredicate()
{
    // work out if it is valid for this to be called or not
    return (someRule == true); // or whatever
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号