我有这个列表框:
<ListBox Name="lstEmployee"
FontSize="32"
SelectionChanged="lstEmployee_SelectionChanged"
Margin="10,60,10,78"
Grid.RowSpan="2"
Foreground="#FF3F575D">
它是这样填充的:
foreach (var contactdata in RootObject_1.results)
{
StackPanel stk = new StackPanel();
stk.Name = "stack" + ctr.ToString();
stk.Orientation = System.Windows.Controls.Orientation.Vertical;
stk.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
TextBlock txtBlk = new TextBlock();
txtBlk.Name = "txtBlk" + ctr.ToString();
txtBlk.Text = contactdata.name;
txtBlk.FontSize = 30;
txtBlk.FontWeight = System.Windows.FontWeights.Bold;
txtBlk.VerticalAlignment = System.Windows.VerticalAlignment.Center;
txtBlk.TextWrapping = TextWrapping.Wrap;
TextBlock txtBlk1 = new TextBlock();
txtBlk1.Name = "txtBlk" + ctr.ToString();
txtBlk1.Text = contactdata.formatted_address;
txtBlk1.FontSize = 22;
txtBlk1.VerticalAlignment = System.Windows.VerticalAlignment.Center;
txtBlk1.TextWrapping = TextWrapping.Wrap;
stk.Children.Add(txtBlk); // index 0
stk.Children.Add(txtBlk1); // index 1
lstEmployee.Items.Add(stk);
referenceList.Add(contactdata.reference.ToString());
}
如何使用图像更改所选项目的背景?("\Image\Taxi\800\cellselect_800")
更新
为了发出 JSON 请求,我正在使用这个:
void chamaTaxi()
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("https://maps.googleapis.com/maps/api/place/textsearch/json?&query=taxi&location=-19.94549444,-43.92314218&&radius=5000&sensor=true&key=AIzaSyDucC8QBV5wu4V-dQXFfABXGaaUzdmT5xw"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(()=>
{
var RootObject_1 = JsonConvert.DeserializeObject<RootObject_1>(e.Result);
**code above**
}
}