1 <ListBox Name="lstFileManager" Background ="Transparent" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True">
2 <ListBox.ItemsPanel>
3 <ItemsPanelTemplate>
4 <WrapPanel/>
5 </ItemsPanelTemplate>
6 </ListBox.ItemsPanel>
7 <ListBox.ItemTemplate>
8 <DataTemplate>
9 <Grid Margin="10" Width="100" Height="120">
10 <Grid.RowDefinitions>
11 <RowDefinition Height="Auto" ></RowDefinition>
12 <RowDefinition Height="Auto" ></RowDefinition>
13 </Grid.RowDefinitions>
14 <Image Source="{Binding Pic}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100"/>
15 <TextBlock Text="{Binding Name}" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Height="20"/>
16 </Grid>
17 </DataTemplate>
18 </ListBox.ItemTemplate>
19 </ListBox>
XAML
1 public class LVData
2 {
3 public string Name {
get;
set; }
4 public string Pic {
get;
set; }
5 }
6 ObservableCollection<LVData> LVDatas =
new ObservableCollection<LVData>
();
7
8 public void BindFileManager(){
9 lstFileManager.ItemsSource =
LVDatas;
10 }
数据绑定
1 BindFileManager();
2 LVDatas.Add(
new LVData { Name =
"图片", Pic =
"http://www.google.com/intl/en_ALL/images/logo.gif" });
3 LVDatas.Add(
new LVData { Name =
"图片", Pic =
"http://www.google.com/intl/en_ALL/images/logo.gif" });
动态更改元素(先绑定数据 然后更改数据)
转载于:https://www.cnblogs.com/zymah/p/3149614.html
相关资源:JAVA上百实例源码以及开源项目