【发布时间】:2017-01-08 23:26:37
【问题描述】:
在发布这个问题之前我已经搜索了很多,但我没有找到任何合理的解决方案。
我正在尝试使用 ItemsControl 创建包含文本框的网格。 这是我的xml:
<ScrollViewer>
<ItemsControl x:Name="grid">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding CatalogName}"></TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
我已将目录列表分配给grid。这是我的代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetCatalog();
}
async void GetCatalog()
{
using (var client = new ApiClientT1())
{
var data = await client.GetCatalogList();
if (data.Success)
{
grid.DataContext = data.Catalogs;
}
//TODO: Handling Errors/Exceptions
}
}
}
但是当我运行程序时它没有显示任何数据。 有什么问题吗?
【问题讨论】:
标签: c# asp.net wpf data-binding