[UWP] ListView自定义限制或错误 [英] [UWP] ListView customization limitation or bug

查看:64
本文介绍了[UWP] ListView自定义限制或错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与WPF不同,UWP ListView不允许在ListViewItem的Content属性中设置自定义元素。

Unlike WPF, UWP ListView doesn't allow setting a custom element in the Content property of a ListViewItem.

if覆盖&#bsp; PrepareContainerForItemOverride方法并设置项目的内容

if you override the PrepareContainerForItemOverride method and set the Content of the item

protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
    base.PrepareContainerForItemOverride(element, item);
    var listItem = element as ListViewItem;
    listItem.Content = myCustomElement;
}

ListView最终会覆盖Content属性,无法在ListViewItem中设置自定义元素。

The ListView ends up overwritting the Content property making impossible to set custom elements inside ListViewItem's.

这是限制还是错误?任何解决方法?

Is this a limitation or bug? Any workaround?

问候,

Alvaro。

Alvaro Rivoir

Alvaro Rivoir

推荐答案

Hello Alvaro,

Hello Alvaro,

我'通过设置数据模板然后将项目列表绑定到列表视图,在ListView中有自定义控件。这听起来像你要找的吗?

示例:
$

I've had custom controls in the ListView, by setting the data template then binding a list of items to the List View. Does this sound like what you're looking for?
Example:

<ListView x:Name="ListView" Grid.Row="1" ItemsSource="{Binding MyList, ElementName=root}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <local:MyUserControl1/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


这篇关于[UWP] ListView自定义限制或错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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