在 XAML 中显示动态大小列表(只读) [英] Showing a dynamic size list in XAML (readonly)

查看:22
本文介绍了在 XAML 中显示动态大小列表(只读)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中显示属性"列表.属性只是一个名称/值对.属性的数量是动态的.

I want to show a list of "properties" in my application. A property is simply a name/value pair. The number of properties is dynamic.

这样做的最佳方法是什么?我唯一能想到的就是创建一个带有 ItemTemplate 的 ListView.但是这些项目是可选择的,这不是我想要的.如果我将列表设为只读,它就会变成灰色.也不喜欢.

The best way to do this? The only thing I can come up with is creating a ListView with an ItemTemplate. But then the items are selectable, and that's not what I want. If I make the list read-only, it becomes gray. Don't like that either.

有人有更好的建议吗?

推荐答案

<ScrollViewer>
    <ItemsControl ItemsSource="{Binding Properties}">
        <ItemsControl.ItemTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}"/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>

如果您希望所有项目都很好地对齐,请为 ItemsControl.ItemsPanel 使用 GridSharedSizeGroup.

Use a Grid for ItemsControl.ItemsPanel with SharedSizeGroup if you want all items to line up nicely.

这篇关于在 XAML 中显示动态大小列表(只读)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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