图片未在listpicker wp7中显示

时间:2014-03-08 09:02:52

标签: c# windows-phone-7 windows-phone

我陷入了困境。我想在listpicker wp7中绑定图像和文本数据。但是当我将图像和文本绑定到listpicker时,只有文本绑定。图像没有绑定。

这是我的代码:

public void loadvehicaltype()
        {
            List<vehical> listofvehical = new List<vehical>();

            listofvehical.Add(new vehical() { CarType= "Any Vehical"   });
            listofvehical.Add(new vehical() { CarType = "test1", carImage = "Images/car_Images/test_yellow.png" });
            listofvehical.Add(new vehical() { CarType = "test2"   });
            listofvehical.Add(new vehical() { CarType = "Any Vehical" });


            this.listPickerVehicalType.ItemsSource = listofvehical;
        }

这是车辆类:

public class vehical
    {

        public string CarType { get; set; }
        public string carImage { get; set; }
    }

这是XAML:

 <toolkit:ListPicker x:Name="listPickerVehicalType" Tap="listPickerVehicalType_Tap" SelectionMode="Single" ItemTemplate="{StaticResource ListPickerItemTemplate}" FullModeItemTemplate="{StaticResource ListPickerFullModeItemTemplate}"   FullModeHeader="Items" CacheMode="BitmapCache"/>

<DataTemplate x:Name="ListPickerItemTemplate">

            <StackPanel Orientation="Horizontal">

                <TextBlock Text="{Binding CarType}" Margin="10 0 0 0"/>
                <!--<Image Source="{Binding carImage}" Margin="10,0,0,0" Stretch="None" />-->

            </StackPanel>

        </DataTemplate>

        <DataTemplate x:Name="ListPickerFullModeItemTemplate">

            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding CarType}" Margin="10,0,0,0"/>
                <Image Source="{Binding carImage}"  />
             </StackPanel>

        </DataTemplate>

请帮我解决这个问题。我搜索这个问题,但没有找到结果

1 个答案:

答案 0 :(得分:0)

这是因为您的图像将其构建操作设置为Resource(这是默认值)。你切换到内容: 右键单击您的图像并将其构建操作设置为内容

Follow these link for more help

Follow these link for more help