Silverlight - Attached Behavior + Command

CAL(Prism)Command绑定
CAL(Prism)中的Command绑定可用于将button的click事件与ViewModel中的方法连接起来。在Silverlight中,该功能仅限于ButtonBase的Click事件。对于其他控件或事件,需要自定义AttachedBehavior。通过继承CommandBehaviorBase<T>,可以创建监测特定控件状态并触发相应命令的行为。

CAL (Prism)中的Command绑定非常好用,可以将某个button的click事件绑定到ViewModel中的某个方法上,简单明了。但是,

CAL (Prism)中的Commands对Silverlight的支持有一个限制 ,只实现了对ButtonBase的Click事件的Command Binding:


The command support in Silverlight is built using an attached behavior pattern. This pattern connects events raised by controls to code on a Presenter or PresentationModel. In WPF and Silverlight, an attached behavior is comprised of two parts: an attached property and a behavior object. The attached property establishes a relationship between the target control and the behavior object. The behavior object monitors the target control and takes action based on events or state change in the control. For example, the Composite Application Library provides an attached behavior that executes commands from the Click event of ButtonBase.

对其他控件中的事件则需要自己来实现:

Frequently, applications need to invoke commands from controls or events other than the Click event from ButtonBase . In these cases, you need to define your own attached property and behavior. The Composite Application Library provides a CommandBehaviorBase <T> to make it easier to create behaviors that interact with ICommands . This class invokes the command and monitors changes in the command's CanExecuteChanged event, and can be used to extend command support in both Silverlight and WPF.

To create your custom behavior, create a class that inherits from CommandBehaviorBase <T> and targets the control you want to monitor. In the constructor of your class, you will need to subscribe to the events you want to monitor from the control.

这个实现其是Attached Behavior 与 CAL (Prism)中Command的一个结合。这里有一个例子

关于Attached Behavior

MATLAB主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性内容概要:本文主要介绍了一种在MATLAB环境下实现的主动噪声和振动控制算法,该算法针对较大的次级路径变化具有较强的鲁棒性。文中详细阐述了算法的设计原理与实现方法,重点解决了传统控制系统中因次级路径动态变化导致性能下降的问题。通过引入自适应机制和鲁棒控制策略,提升了系统在复杂环境下的稳定性和控制精度,适用于需要高精度噪声与振动抑制的实际工程场景。此外,文档还列举了多个MATLAB仿真实例及相关科研技术服务内容,涵盖信号处理、智能优化、机器学习等多个交叉领域。; 适合人群:具备一定MATLAB编程基础和控制系统理论知识的科研人员及工程技术人员,尤其适合从事噪声与振动控制、信号处理、自动化等相关领域的研究生和工程师。; 使用场景及目标:①应用于汽车、航空航天、精密仪器等对噪声和振动敏感的工业领域;②用于提升现有主动控制系统对参数变化的适应能力;③为相关科研项目提供算法验证与仿真平台支持; 阅读建议:建议读者结合提供的MATLAB代码进行仿真实验,深入理解算法在不同次级路径条件下的响应特性,并可通过调整控制参数进一步探究其鲁棒性边界。同时可参考文档中列出的相关技术案例拓展应用场景。
### 排查Cinder Volume状态为Error的原因及解决方案 当Cinder Volume的状态变为`error`时,这通常是由于某种异常情况引起的。以下是一些常见的原因及其对应的解决方法。 #### 可能的原因及解决措施 ##### 1. 卷删除失败 如果卷在删除过程中出现问题,可能会导致其状态变为`error_deleting`或最终转为`error`。这种情况下,可以尝试手动修改卷的状态并重新删除。 - 修改卷状态为`error`: ```bash [root@controller ~]# cinder reset-state --state error <volume-id> ``` - 删除有问题的卷: ```bash [root@controller ~]# cinder delete <volume-id> ``` - 如果仍然无法删除,可以直接强制删除: ```bash [root@controller ~]# cinder force-delete <volume-id> ``` 这些命令可以帮助清理卡住的卷资源[^1]。 ##### 2. 后端存储连接问题 有时,计算节点与卷之间的链接未能正确释放,可能导致卷进入错误状态。此时需要检查后端存储的日志文件(如LVM日志或其他存储插件的日志),寻找潜在的错误信息。 - 对于LVM后端,验证是否有足够的空间可用,并确保卷组已正确定义: ```bash [root@compute ~]# vgs ``` - 如果发现卷组容量不足,扩展逻辑卷或将数据迁移到其他位置可能是必要的解决方案之一[^3]。 ##### 3. Cinder Driver Bug 或兼容性问题 某些版本可能存在驱动程序缺陷,特别是Red Hat OpenStack Platform中报告过的Bug(例如[Bugzilla ID:888987](https://bugzilla.redhat.com/show_bug.cgi?id=888987))。在这种情形下,升级至最新稳定版或者应用补丁将是首要考虑事项。 - 检查现有环境使用的软件包版本号: ```bash [root@controller ~]# rpm -qa | grep openstack-cinder ``` - 根据官方文档指导完成相应组件更新过程[^4]。 ##### 4. 数据库一致性损坏 偶尔也会因为数据库记录不一致而导致此类现象发生。建议备份好原始资料后再执行修复动作。 - 清理残留条目前先停止服务以防冲突; - 利用DB工具扫描表结构差异找出矛盾之处加以修正; --- ### 实现脚本化批量处理 为了简化重复性的维护作业流程,下面提供一段Python脚本来自动检测所有处于非正常状况下的实例并采取预设好的应对策略: ```python from cinderclient import client import os def get_cinder_client(): auth_url = "http://<keystone-host>:5000/v3" username = "<your-admin-user>" password = "<your-password>" tenant_name = "<your-project-name>" sess = session.Session(auth=(auth_url, (username, password)), project_name=tenant_name) return client.Client('3', session=sess) if __name__ == "__main__": cc = get_cinder_client() volumes = cc.volumes.list(search_opts={'all_tenants': True}) for vol in volumes: if vol.status.lower() in ['error', 'error_deleting']: try: print(f"Resetting state of volume {vol.id} from '{vol.status}' to 'available'") cc.volumes.reset_state(vol.id, 'error') choice = input("Do you want to attempt deletion now? y/n ") if choice.strip().lower()[0]=='y': cc.volumes.force_delete(vol.id) except Exception as e: print(e) ``` 注意替换模板内的占位符以适配实际部署场景需求[^3]. --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值