Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试检索图像时不显示图片_C#_Wcf_Windows Phone 7 - Fatal编程技术网

C# 尝试检索图像时不显示图片

C# 尝试检索图像时不显示图片,c#,wcf,windows-phone-7,C#,Wcf,Windows Phone 7,我在数据库中的图像没有显示在Windows phone上。 我只能在列表中获取EmpNo,但是图像没有显示在我的列表框中。 我的编码有问题吗 我在MainPage.xaml上的编码是 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Grid.Resources> <src:ImageConverter x:Key="imgConverter"/>

我在数据库中的图像没有显示在Windows phone上。 我只能在列表中获取EmpNo,但是图像没有显示在我的列表框中。 我的编码有问题吗

我在MainPage.xaml上的编码是

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.Resources>
            <src:ImageConverter x:Key="imgConverter"/>
        </Grid.Resources>
        <ListBox Height="650" HorizontalAlignment="Left" Margin="11,17,0,0" Name="listBox1" VerticalAlignment="Top" Width="434" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding EmpNo}"/>
                        <Image Grid.Column="1" Grid.Row="4" Height="136" HorizontalAlignment="Left"
               Margin="16,16,0,0" Name="imgEmp" Stretch="Fill"
               VerticalAlignment="Top" Width="200"
                Source="{Binding EmpImage}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
 </Grid>
我在mainpage.xaml.cs上的代码是

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();
        Service1Client svc = new Service1Client();
        svc.GetAllModelsCompleted += new EventHandler<GetAllModelsCompletedEventArgs>(svc_GetAllModelsCompleted);
        svc.GetAllModelsAsync();
    }

    void svc_GetAllModelsCompleted(object sender, GetAllModelsCompletedEventArgs e)
    {
        listBox1.ItemsSource = e.Result;
    }
}
public class ImageConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var memStream = new MemoryStream((byte[])value);
        memStream.Seek(0, SeekOrigin.Begin);
        var empImage = new BitmapImage();
        empImage.CreateOptions = BitmapCreateOptions.None;
        empImage.SetSource(memStream);
        return empImage;
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
  }

尝试应用转换器:

Source="{Binding EmpImage, Converter={StaticResource imgConverter}}"

thnx。但是现在有另一个错误invalidCastException未在var memStream=new MemoryStreambyte[]值处处理@那么您的值不能转换为字节数组。@browneyeo我不明白您在说什么,但请您自己调试这个问题。在转换器中放置一个断点,并通过检查所有变量和单步执行代码来检查为何无法将值转换为图像。静态成员CreateOptionProperty的局部变量show me无法获取字段“CreateOptionProperty”的值,因为有关包含类的信息不完整不可用。System.Windows.DependencyProperty&UriSourceProperty无法获取字段“UriSourceProperty”的值,因为有关包含类的信息不可用。System.Windows.DependencyProperty。这意味着什么?