通用应用程序:如何将 ListViewItem(容器)的属性绑定到实际项目(视图模型)? [英] Universal Apps: How to bind a property of a ListViewItem (container) to the actual item (View Model)?

查看:20
本文介绍了通用应用程序:如何将 ListViewItem(容器)的属性绑定到实际项目(视图模型)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个ListView

<ListView ItemsSource="{Binding Items}">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Background" Value="{Binding IsValid, Converter={StaticResource BooleanToBrushConverter}" />
        </Style>
    </ListView.ItemContainerStyle>
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

我知道绑定不适用于通用应用程序中的 Setter,但是,如何将项目的容器与项目本身绑定?如果不能提供任何逻辑,只能提供常量值,那么创建自定义容器有什么意义?

I know bindings don't work for Setters in Universal Applications but, then how do I bind a the container of an item with the item itself? What's the point of creating a custom container if you cannot provide any logic, but constant values?

推荐答案

好的,你不能使用正常的方式绑定到 DataContext,但是你可以使用其他(智能)方法来做到:

OK, you can't bind to the DataContext using the normal ways, but you can do it using other (smart) methods:

请参阅这篇文章.它提供了一个帮助器",允许使用 Setter 绑定到 DataContext.

See this post. It provides a "helper" that allows to bind to the DataContext with a Setter.

这篇关于通用应用程序:如何将 ListViewItem(容器)的属性绑定到实际项目(视图模型)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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