相关疑难解决方法(0)

如何将数据库列表绑定到WPF/WP7中的ListBox?

我正在尝试将字符串值列表绑定到列表框,以便逐行列出它们的值.现在我用这个:

<ListBox Margin="20" ItemsSource="{Binding Path=PersonNames}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Id}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

但我不知道我应该把什么放入文本块,而不是Id因为它们都是字符串值,而不是自定义类.

它还抱怨当我在MainPage中将它作为MainPage.PersonNames时,不必找到PersonNames.

我将数据上下文设置为:

DataContext="{Binding RelativeSource={RelativeSource Self}}"
Run Code Online (Sandbox Code Playgroud)

我做错了吗?

.net c# data-binding wpf windows-phone-7

61
推荐指数
4
解决办法
13万
查看次数

标签 统计

.net ×1

c# ×1

data-binding ×1

windows-phone-7 ×1

wpf ×1