我有一个Windows Phone应用程序,它使用WCF从SQL服务器获取数据。 数据进入ListBox,并且有一个名为Status的列。 列状态,需要显示图像而不是数字,右边知道我显示0表示成功,1表示警告,2表示警报。 谁能指出我正确的方向? 感谢。
MainPage.xaml.cs中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using NSSPhoneApp.NSSServiceReference;
using System.ServiceModel;
namespace NSSPhoneApp
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
NSSServiceClient client = new NSSServiceClient();
client.GetAllServer_LogsCompleted +=
new EventHandler<GetAllServer_LogsCompletedEventArgs>(client_GetAllServer_LogsCompleted);
client.GetAllServer_LogsAsync();
}
void client_GetAllServer_LogsCompleted(object sender, GetAllServer_LogsCompletedEventArgs e)
{
if (e.Error == null)
{
lst.ItemsSource = e.Result;
}
}
}
}
仅限MainPage.xaml ContentPanel
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Height="Auto" HorizontalAlignment="Stretch" Margin="0,0,0,6" Name="lst" VerticalAlignment="Stretch" Width="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Status}" Margin="12,0,12,0"/>
<TextBlock Text="{Binding Name}" Margin="12,0,12,0"/>
<TextBlock Text="{Binding IP}" Margin="12,0,12,0"/>
<TextBlock Text="{Binding Task}" Margin="12,0,12,0"/>
<TextBlock Text="{Binding Message}" Margin="12,0,12,0"/>
<TextBlock Text="{Binding Time}" Margin="12,0,12,0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
答案 0 :(得分:0)
未经测试,您必须弄清楚如何正确显示图像。
listBox.Controls.Add(new Label() { Text = "Status: ", Image = System.Drawing.Image.FromFile(status == "0" ? "succes.png" : status == "1" ? "warning.png" : "alarm.png") });