什么是Silverlight中DataTrigger的替代品 [英] What is the replacement for DataTrigger in Silverlight
问题描述
这是我的情况.
我有2个属性.类型和状态.
I have 2 Properties. Type and State.
Type是具有3个值的枚举,例如,球,汽车,箭头. State是一个整数,可以接受3个状态值,例如-1、0、1.此外,每个状态值都有9张图片.
Type is an Enum with 3 values eg, ball, car, arrow. State is an int which would accept 3 state values eg., -1, 0, 1. Also, I have 9 images for each state values.
例如,如果我将类型选择为ball,将值选择为-1,则我想显示一个红色的球. 如果我选择type作为箭头,而value选择为1,我想显示一个向上箭头.等等,
Like, if I select type as ball and value as -1, I want to display a Red color ball. If I select type as arrow and value as 1, I want to display a up arrow. etc.,
我能够在WPF中做到这一点.我创建了3个带有空图像的DataTemplates.然后,我使用DataTrigger检查并更新所选StateValue的特定图像.
I'm able to do this in WPF. I created 3 DataTemplates with an empty Image. Then, I use DataTrigger to check and update the particular image for the selected StateValue.
但是,在Silverlight中,我该怎么做.我知道,我必须在VSM中执行此操作.但是,我想了解有关此(或任何可用替代方案)的更多详细信息.
But, in silverlight how can I do this. I know, I have to do it in VSM. But, I would like to know some more details regarding this (or) any alternatives available.
推荐答案
我只使用一个转换器,该转换器使用具有2个属性的对象并返回图像.纯XAML中的此类代码很痛苦,而且确实属于C#.
I'd just use a converter that takes your object with 2 properties and returns an image. Code like that in pure XAML is painful and really belongs in C#.
这篇关于什么是Silverlight中DataTrigger的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!