如何将两个不同的数据集合绑定到 2 个不同的 PanoramaItem 列表框中?
我有 AItems 和 BItems,想要绑定到 PanoramaItem 中的 AListBox 和另一个 PanoramaItem 中的 BListBox。
我在每个 ListBox 中指定了 ItemsSource
<controls:PanoramaItem>
<ListBox ItemsSource="{Binding AItems}" >
...
</ListBox>
</controls:PanoramaItem>
<controls:PanoramaItem
<ListBox ItemsSource="{Binding BItems}" >
...
</ListBox>
</controls:PanoramaItem>
如何从代码隐藏将数据绑定到每个 ListBox?
我有构造函数方法
public MainPage()
{
InitializeComponent();
}
和页面加载方法
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
}
谢谢。
I have AItems and BItems, want to bind to AListBox in a PanoramaItem and BListBox in another PanoramamItem.
I specified ItemsSource in each ListBox
<controls:PanoramaItem>
<ListBox ItemsSource="{Binding AItems}" >
...
</ListBox>
</controls:PanoramaItem>
<controls:PanoramaItem
<ListBox ItemsSource="{Binding BItems}" >
...
</ListBox>
</controls:PanoramaItem>
How do I bind the data to each ListBox from code behind?
I have the Constructor method
public MainPage()
{
InitializeComponent();
}
and page load method
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将集合绑定到代码隐藏中的控件:
1) 指定列表框名称.ItemsSource =;
2) 在后面的代码中,设置
(您应该确保您的集合是 ObservableCollection以确保如果集合发生更改,这会反映在视图中。)
例如...
然后
您可以从以下位置调用
BindMyControls()
最合适的地方,很可能是在收藏品被填充之后。To bind the collections to controls in code-behind :
1) Give the listboxes names
2) in code behind, set <listboxName>.ItemsSource = <collection>
(You should make sure your collections are ObservableCollection<myType> to ensure that if the collection changes, this is reflected in the view.)
for example...
and then
Then you can call
BindMyControls()
from the most appropriate place, most likely once the collections have been populated.