Ich arbeite an einem Windows-Gadget, das eine Liste von sharepoint mein Code hinter funktioniert und die Daten von Sharepoint sammeln. und mein XAML-Code sollte die Liste in einer Listbox anzeigen, aber die Art, wie ich sie gebunden habe, zeigt die Daten mit einem Buchstaben für Zeile und nur mit dem ersten Element. Ich weiß nicht warum.wpf ListBox Binding ObservableCollection zeige alle vermasselten Daten
Das ist mein xml-Code
<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>
und dies ist mein Code hinter:
//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
}
}
Danke für Ihre Hilfe,
Vielen Dank für das – user1315345