我能够检索数据。但是我不能将这些数据绑定到我的列表框中。
XAML文件代码
<ListBox Grid.Row="1" Height="Auto" HorizontalAlignment="Left" Margin="12,140,0,0" Name="lb_AllActivity" VerticalAlignment="Top" Width="Auto" FontFamily="Tahoma" FontSize="25">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Border Margin="3">
<StackPanel Background="Transparent" Orientation="Vertical" Width="420" Height="60">
<StackPanel Background="Transparent" Orientation="Horizontal" Width="420" Height="60">
<TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding DateTime}"></TextBlock>
<TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding Amt}"></TextBlock>
<TextBlock Foreground="White" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding Msg}"></TextBlock>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的CS FIle中有以下代码
public partial class Activities : PhoneApplicationPage
{
DatabaseService.ServiceSoapClient dbService = new DatabaseService.ServiceSoapClient();
public Activities()
{
InitializeComponent();
InitializeComponent();
dbService.getAllActivityAsync("Russell Loh");
dbService.getAllActivityCompleted += new EventHandler<DatabaseService.getAllActivityCompletedEventArgs>(dbService_getAllActivity);
}
public class AllActivity
{
public string TransID { get; set; }
public string Amt { get; set; }
public string Cat { get; set; }
public string SharedNo { get; set; }
public string Msg { get; set; }
public string DateTime { get; set; }
}
void dbService_getAllActivity(object sender, DatabaseService.getAllActivityCompletedEventArgs e)
{
if (e.Error == null)
{
string result = e.Result;
string[] arrayActivity = result.Split('~');
string[] transID = arrayActivity[0].Split('#');
string[] amount = arrayActivity[1].Split('#');
string[] category = arrayActivity[2].Split('#');
string[] sharedNum = arrayActivity[3].Split('#');
string[] message = arrayActivity[4].Split('#');
string[] dateTime = arrayActivity[5].Split('#');
List<String> Activitylist = new List<String>();
for (int i = 0; i < transID.Length; i++)
{
string TransID = transID[i];
string Amt = amount[i];
string Cat = category[i];
string SharedNo = sharedNum[i];
string Msg = message[i];
string DateTime = dateTime[i];
//Activitylist.Add(DateTime + " $" + Amt);
Activitylist.Add(DateTime);
Activitylist.Add(Msg);
Activitylist.Add(Amt);
}
lb_AllActivity.ItemsSource = Activitylist;
}
}
答案 0 :(得分:1)
虽然我不是100%肯定你在这里想做什么,但我认为......
您没有正确填充ActivityList
或ItemsSource
ListBox
for (int i = 0; i < transID.Length; i++)
{
string TransID = transID[i];
string Amt = amount[i];
string Cat = category[i];
string SharedNo = sharedNum[i];
string Msg = message[i];
string DateTime = dateTime[i];
//create a new instance of activity
AllActivity activity = new AllActivity();
activity.Amt = Amt;
activity.Msg = Msg;
activity.DateTime = DateTime;
ActivityList.Add(activity);
}