问题描述
这是我的场景.
我有 2 个属性.类型和状态.
I have 2 Properties. Type and State.
Type 是具有 3 个值的枚举,例如球、汽车、箭头.State 是一个 int 类型,它可以接受 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.
比如,如果我选择类型为球,值选择为 -1,我想显示一个红色的球.如果我选择类型为箭头,值选择为 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 的替代品是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!