您可以使用WPF WHERE子句 - XAML绑定? [英] Can you use a Where Clause in WPF - XAML Binding?

查看:514
本文介绍了您可以使用WPF WHERE子句 - XAML绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想图像源列表项绑定,但我需要绑定选择从基于一个参数列表中的图像 - 选择基于列表中的布尔值列表中的图片

I want to bind an image source to a List item, but I need the binding to select an image from the list based on an argument - select the image from the List based on a boolean value within the list.

例如

图片列表中包含了若干领域:

Images List has a number of fields:

Images.Src
Images.IsMainImage(真/假)

Images.Src Images.IsMainImage (True/False)

等。

我想我绑定到从列表中选择图像的基础上,IsMainImage = TRUE。

I want my Binding to select the image from the List, based on IsMainImage = True.

是否有可能还是我只能这样做了转换?

Is it possible or can I only do this with a Converter?

我希望会有某种方式在绑定或类似的东西使用LINQ。

I was hoping there would be some sort of way to use LINQ in the Binding or something like that.

推荐答案

所有你能做的就是使用转炉或隐藏使用触发器(这意味着他们是present ItemsControl中装入的ItemsControl的项目,但不可见) - 它不应该是一个大问题,如果没有太多的项目

All you can do is to use the converter or hide the items loaded into the ItemsControl using a trigger (it means they are present in the ItemsControl, but not visible) - it should not be a big deal if there aren't too many of the items.

也许这将有可能写这将需要一个LINQ前pression字符串形式的自定义绑定类,编译广告用它来处理边界集合,但是这将是巨大的矫枉过正。而将可能导致不好的编程习惯(编码更多的业务逻辑到XAML)。

Maybe it would be possible to write a custom Binding class which would take a LINQ expression in string form, compile it ad use it to process the bound collection, but that would be colossal overkill. And would potentially lead to bad programming practices (coding more business logic into the XAML).

这篇关于您可以使用WPF WHERE子句 - XAML绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆