在 WPF MVVM 中使用行为? [英] Use of Behavior in WPF MVVM?

查看:31
本文介绍了在 WPF MVVM 中使用行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WPF MVVM 的新手 .. 有没有人清楚 WPF 中 MVVM 应用程序中行为的用法?.为什么即使我们在 WPF MVVM 中有方法操作,我们也应该选择 Behavior ?

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 ?

推荐答案

行为是您附加到元素并指定应用程序何时响应的东西.

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

Action 附加到行为上,定义了当行为被触发时应用程序应该做什么.

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

来自这篇文章:

乍一看,一个行为看起来类似于一个动作:一个独立的功能单元.主要区别在于行动期望被调用,当被调用时,它们会执行一些操作.一个行为没有调用的概念;相反,它起作用更多地作为对象的附加组件:可以是可选的功能如果需要,附加到对象上.它可能会做某些事情作为回应来自环境的刺激,但不能保证用户可以控制这个刺激是什么:这取决于行为作者确定什么可以定制,什么不可以定制.

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.

来自这篇文章:

行为让你封装多个相关或依赖的活动在单个可重用单元中加上状态.

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

这篇关于在 WPF MVVM 中使用行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆