我正在开发一个 Windows 小工具,它将显示来自 sharepoint 的列表,我背后的代码运行良好,并从 sharepoint 收集数据。并且我的 xaml 代码应该在列表框中显示列表,但我绑定它的方式显示数据是逐行显示的,并且只是第一项。不知道为什么。
这是我的 xml 代码
<Page x:Class="TipsList.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ListBox Name="ListboxTips" Width="Auto" ItemsSource="{Binding StateTitle}" />
<StackPanel Grid.Column="1">
<Button Click="OnLoad">_Load</Button>
</StackPanel>
</Grid>
</Page>
这是我背后的代码:
//The Url
siteUrl = "http://site/SandBox";
//The Site Context using ClientContext class
//This will create a Client connection to Web Application
clientContext = new SPSClient.ClientContext(siteUrl);
//The Web Site to Open
clientWeb = clientContext.Web;
var salesInfoList = clientContext.Web.Lists.GetByTitle("Tips");
//Define the CAMLQuery this will be used to Query to the List
SPSClient.CamlQuery Query = new SPSClient.CamlQuery();
SPSClient.ListItemCollection listData = salesInfoList.GetItems(Query);
//Now Execute the Query
var queryResultSaleListItems = clientContext.LoadQuery(listData);
clientContext.ExecuteQuery();
//Read the Data into the Object
var TipsList = from Sales in queryResultSaleListItems
select Sales;
ObservableCollection<Tips> colTips = new ObservableCollection<Tips>();
//Read Every List Item and Display Data into the DataGrid
foreach (SPSClient.ListItem item in TipsList)
{
var tips = new Tips();
tips.StateTitle = item.FieldValues.Values.ElementAt(2).ToString();
tips.ProductName = item.FieldValues.Values.ElementAt(4).ToString();
tips.Quantity = item.FieldValues.Values.ElementAt(5).ToString();
colTips.Add(tips);
}
ListboxTips.DataContext = colTips;
}
catch (Exception ex)
{
// Log error (including InnerExceptions!)
// Handle exception
}
}
谢谢你的帮助,