Use of Behavior in WPF MVVM?

前端 未结 3 1856
北荒
北荒 2020-12-15 11:03

I am new to WPF MVVM .. Anybody clear the usage of the Behaviors in MVVM application in WPF?. Why we should go for Behavior even we have Method action in WPF MVVM ?

3条回答
  •  甜味超标
    2020-12-15 11:19

    A Behavior is the thing you attach to an element and specifies when the application should respond.

    The Action is attached to the behavior and defines what the application should do when the behavior is triggered.

    From this article:

    At a glance, a behavior looks similar to an action: a self-contained unit of functionality. The main difference is that actions expect to be invoked, and when invoked, they will perform some operation. A behavior does not have the concept of invocation; instead, it acts more as an add-on to an object: optional functionality that can be attached to an object if desired. It may do certain things in response to stimulus from the environment, but there is no guarantee that the user can control what this stimulus is: it is up to the behavior author to determine what can and cannot be customized.

    And from this article:

    Behaviors let you encapsulate multiple related or dependent activities plus state in a single reusable unit.

提交回复
热议问题