Silverlight 绑定转换器
我正在尝试将一个字段绑定到我的隐蔽器...但这似乎是不可能的...
这就是我正在尝试做的。
Source="{Binding LeaveApproved,Converter={StaticResource CommentTypeIconConverter},ConverterParameter={Binding TypeOfWorkId}}"
当 TypeOfWorkId 为 5 并且 LeaveApproved 为 null 时,我想要一个不同的图标。所有其他类型的工作都应该有一个空字段,因此那里没有图标。这就是为什么我需要在我的 coverter 中使用 typeOfWorkId 。
有人知道如何做到这一点吗?
格茨
I'm trying to bind a field to my coverter... But it seems like it's not possible...
This is what I'm trying to do.
Source="{Binding LeaveApproved,Converter={StaticResource CommentTypeIconConverter},ConverterParameter={Binding TypeOfWorkId}}"
I want a different icon for when the TypeOfWorkId is 5 and the LeaveApproved is null. All the other Types of work should have an empty field, so no icon there. That's why I need the typeOfWorkId in my coverter.
Has anybody have any idea how to do this?
Grtz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ConvertParameter 中无法进行绑定(尽管您可以使用 StaticResource)。
要解决您的情况,您必须创建另一个属性,例如 LeaveApprovedTypeOfWorkId ,它将考虑您的逻辑。
改为绑定到此属性。
如果LeaveApproved或设置了TypeOfWorkId,请不要忘记NotifyPoppertyChange
Binding is not possible in ConvertParameter (though you can use StaticResource).
To solve your case you will have to create another Property say LeaveApprovedTypeOfWorkId which will take into account you logic.
Bind to this property instead.
Do not forget to NotifyPoppertyChange in case of LeaveApproved or TypeOfWorkId is set
不要设置对象的属性,您将在转换中拥有您的对象。就像这样:
Dont set the property of the object and You will have your object in your convert. Just like that:
这对你有用吗?
更好的做法是使用多重绑定。
对于您想要做的事情, -mutiple-bindings-to-a-single-property/" rel="nofollow">http://www.scottlogic.co.uk/blog/colin/2009/06/silverlight-multibindings-how-to-attached-多个绑定到单个属性/
Does this work for you?
It is better practice to use multibinding though for what you want to do..
http://www.scottlogic.co.uk/blog/colin/2009/06/silverlight-multibindings-how-to-attached-mutiple-bindings-to-a-single-property/