2011-07-20 31 views
0

不顯示在我的應用我想顯示一個列表框,它是通過數據綁定鏈接到的對象內部的圖像。 但是,由於某種原因圖片沒有顯示出來,我似乎無法發現錯誤。 我知道圖片在對象中,因爲如果我將一個新的Image對象添加到XAML中,並且在代碼中將其源設置爲來自對象的其中一個圖片,則會顯示它。圖片在網格

下面是我的步驟的代碼:

 foreach (Indtastning indt in listBoxIndhold.ItemsSource) 
     { 
      byte[] data = Convert.FromBase64String(indt.imageName); 
      Stream memStream = new MemoryStream(data); 
      WriteableBitmap wbimg = PictureDecoder.DecodeJpeg(memStream); 
      indt.picture = new Image(); 
      indt.picture.Source = wbimg; 
      //Below is my test image, which shows the picture correctly. 
      testimage.Source = indt.picture.Source; 
     } 

我與圖片XAML:

<ListBox x:Name="listBoxIndhold" Grid.Row="0" 
        ItemsSource="{Binding .}" 
        ScrollViewer.VerticalScrollBarVisibility="Visible" > 
      <ListBox.ItemTemplate> 
       <DataTemplate > 
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="False"> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="auto"/> 
          <ColumnDefinition Width="*"/> 
          <ColumnDefinition Width="auto"/> 
          <ColumnDefinition Width="auto"/> 

         </Grid.ColumnDefinitions> 

         <TextBlock Text="{Binding Mode=OneWay, Path=name}" Grid.Column="0" 
             HorizontalAlignment="Stretch" VerticalAlignment="Center" 
             Style="{StaticResource PhoneTextSmallStyle}" 
             TextWrapping="Wrap" FontSize="24"> 
           <toolkit:ContextMenuService.ContextMenu> 
            <toolkit:ContextMenu> 
             <toolkit:MenuItem Tag="{Binding Mode=OneWay, Path=name}" Header="Rediger" Click="MenuItem_Click" /> 
             <toolkit:MenuItem Tag="{Binding Mode=OneWay, Path=name}" Header="Slet" Click="MenuItem_Click_1"/> 
            </toolkit:ContextMenu> 
           </toolkit:ContextMenuService.ContextMenu> 
         </TextBlock> 

         <TextBlock Text="{Binding Mode=OneWay, Path=description}" Grid.Column="1" 
             HorizontalAlignment="Stretch" VerticalAlignment="Center" 
             Style="{StaticResource PhoneTextSmallStyle}" TextWrapping="Wrap" 
             FontSize="24"> 
           <toolkit:ContextMenuService.ContextMenu> 
            <toolkit:ContextMenu> 
             <toolkit:MenuItem Tag="{Binding Mode=OneWay, Path=name}" Header="Rediger" Click="MenuItem_Click" /> 
             <toolkit:MenuItem Tag="{Binding Mode=OneWay, Path=name}" Header="Slet" Click="MenuItem_Click_1"/> 
            </toolkit:ContextMenu> 
           </toolkit:ContextMenuService.ContextMenu> 
         </TextBlock> 

         <Image Source="{Binding Mode=OneWay, Path=picture}" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Width="48" Height="48" /> 

         <TextBlock Text="{Binding Mode=OneWay, Path=amount}" Grid.Column="3" 
             HorizontalAlignment="Stretch" VerticalAlignment="Center" 
             Style="{StaticResource PhoneTextSmallStyle}" 
             FontSize="24" > 
           <toolkit:ContextMenuService.ContextMenu> 
            <toolkit:ContextMenu> 
             <toolkit:MenuItem Tag="{Binding Mode=OneWay, Path=name}" Header="Rediger" Click="MenuItem_Click" /> 
             <toolkit:MenuItem Tag="{Binding Mode=OneWay, Path=name}" Header="Slet" Click="MenuItem_Click_1"/> 
            </toolkit:ContextMenu> 
           </toolkit:ContextMenuService.ContextMenu> 
         </TextBlock> 

        </Grid> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 

我Indtastning類:

[DataContract] 
public class Indtastning 
{ 
    [DataMember] 
    public string name { get; set; } 
    [DataMember] 
    public double amount { get; set; } 
    [DataMember] 
    public string description { get; set; } 
    [DataMember] 
    public bool owes { get; set; } 
    [DataMember] 
    public string id { get; set; } 
    [DataMember] 
    public string imageName; 

    public Image picture; 


    //Constructor 
    public Indtastning(string id , string navn, double beløb, string beskrivelse, bool skylder) 
    { 
     this.name = navn; 
     this.description = beskrivelse; 
     this.amount = beløb; 
     this.owes = skylder; 
     this.id = id; 
    } 
} 

誰能發現我在做什麼這裏錯了嗎? 這真的很煩人,因爲它是啓動應用程序之前我需要排序的最後一件事情之一。

+3

你能提供有關Indtastning類的一些細節,最好在代碼中 - 特別是它實現INotifyChanged,並且是「圖片」的公共屬性? –

+0

問題標題中提到的網格在哪裏? –

+0

用更多代碼更新。我沒有實現INotifyChanged,也許這就是我需要做的事情? –

回答

0

問題解決了很久以前。 看到我上面的評論。

0

您是否將圖像保存爲內容或資源。如果圖像是資源,您將無法看到它,請將其設置爲內容並重試。希望它可以幫助