我工作的一個Windows小工具,它會顯示一個列表從SharePoint 我的身後workd精碼和從SharePoint收集DATAS。 和我的XAML代碼應該會顯示一個列表框列表中,但我已經綁定顯示它與行一個字母,只是第一項數據的方式。不知道爲什麼。WPF列表框綁定的ObservableCollection顯示DATAS全亂了
這是我的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
}
}
感謝您的幫助,
感謝您的 – user1315345 2012-04-11 11:59:03