2010-12-29 7 views
1

私はリストボックスを含むWindows phone 7アプリケーションを持っています。私は、リストボックス内の各アイテムが特定のイメージを持つことを望みます。WP7イメージバインド

<ListBox Height="606" HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Visible" 
       Margin="20,20,0,0" 
       Name="listBox1" VerticalAlignment="Top" Width="414" ItemsSource="{Binding SubList, Mode=OneWay}"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Horizontal"> 
         <Image Height="50" Width="50" 
           VerticalAlignment="Top" Margin="0,10,8,0" Source="{Binding Image, Mode = OneWay}"/> 
         <StackPanel Orientation="Vertical"> 
          <HyperlinkButton Content="{Binding Cathegory, Mode=OneWay}" NavigateUri="" HorizontalAlignment="Right"> 
          </HyperlinkButton> 
         </StackPanel> 
        </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 

ImageコントロールのSourceプロパティにバインドされたプロパティは、Uriです。 私の問題は、画像がリストボックスに表示されないことです。 私はUriの代わりに文字列を使用しようとしましたが、同じ問題が発生します。

私は親切に助けていただきありがとうございます。

答えて

0

この他にチェックSO私はそれはあなたの質問への答えが含まれていると信じて、答える:


Image UriSource and Data Bindingしかし、それの基本は、あなたがのBitmapImageにあなたのURI /文字列を変換する必要があるということです(いずれかのviewmodel経由プロパティ、またはコンバータ)

1

これは動作するはずです:

public class Item 
{ 
    public int Number { get; set; } 

    public Uri ImageUri { get; set; } 

    public Item(int number, Uri imageUri) 
    { 
     Number = number; 
     ImageUri = imageUri; 
    } 
} 
And the datatemplate: 


<ListBox x:Name="Items"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <TextBlock Text="{Binding Number}"></TextBlock> 
       <Image Source="{Binding ImageUri}"></Image> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox>