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

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

问题描述

我是WPF MVVM的新手.有人清除WPF中MVVM应用程序中行为"的用法吗?为什么即使在WPF MVVM中有方法"操作,我们也应该追求行为"?

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.

动作附加到行为,并定义触发行为后应用程序应该执行的操作.

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天全站免登陆