我已經細化了一些代碼。下面是該命名空間聲明
xmlns:vm="clr-namespace:TestSandbox.ViewModels"
DataContext的
<UserControl.DataContext>
<vm:ViewModel1/>
</UserControl.DataContext>
和uniformGrid
<ItemsControl Name="imageList" ItemsSource="{Binding Path=Products}" BorderBrush="#FFA90606" Background="#FFE70F0F">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Margin="50">
</UniformGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- The Image binding -->
<Image Source="{Binding Path=image}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
這裏的視圖模型
public List<Product> Products {get; set; }
public ViewModel1()
{
Products = new List<Product>();
Products.Add(MakeProduct(@"..\images\beemovie.jpg"));
Products.Add(MakeProduct(@"..\images\darkknight.jpg"));
Products.Add(MakeProduct(@"..\images\matrix.jpg"));
Products.Add(MakeProduct(@"..\images\milo.jpg"));
Products.Add(MakeProduct(@"..\images\superhero.jpg"));
Products.Add(MakeProduct(@"..\images\twilight.jpg"));
Products.Add(MakeProduct(@"..\images\xfiles.jpg"));
}
public Product MakeProduct(string path)
{
return new Product(path, MakeImage(path));
}
public BitmapImage MakeImage(string path)
{
BitmapImage bmpi = new BitmapImage();
bmpi.BeginInit();
bmpi.UriSource = new Uri(path, UriKind.Relative);
bmpi.EndInit();
return bmpi;
}
看起來不錯!我會盡快嘗試。 – mico 2010-04-28 16:52:14
是的,這是要走的路。我的動態圖像列表中仍然沒有處理所有的皺紋,但是,它們按照正確的順序出現。 – mico 2010-04-29 11:00:03