我有一个 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>