<Grid Name="contentGrid" Grid.Row="2" Grid.Column="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListBox Name="ImgListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Name="imgSubCloud" Source="{Binding imgPath}" ></Image>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ListBox Height="595" Margin="0,0,-12,0" Name="listBox1" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Grid x:Name="rootaa" Margin="0,0,0,15"> <Grid.ColumnDefinitions> <ColumnDefinition Width="107*"></ColumnDefinition> <ColumnDefinition Width="349*"></ColumnDefinition> </Grid.ColumnDefinitions> <Image Grid.Row="0" Grid.Column="0" Source="{Binding recommendImage}"/> <Image Grid.Row="0" Grid.Column="1" Source="{Binding recommendImage}"/> </Grid> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid>
其中创建两列、然后实例化两个image控件,第一个放在0行0列,第二个放在0行1列、
这样的话,图片就重复了
@菜鸟_001: 不是啊、
<Image Grid.Row="0" Grid.Column="0" Source="{Binding 图片1}"/> <Image Grid.Row="0" Grid.Column="1" Source="{Binding 图片2}"/>
你source的时候绑定不同的image源 不就不会重复了嘛、能不能具体点你的需求?
@Beyond-bit:
我的完整的代码,请帮帮忙,谢谢,图片只能绑定一个绑定
<Grid Name="contentGrid" Grid.Row="2" Grid.Column="0" ShowGridLines="True" > <ListBox Name="ImgListBox"> <ListBox.ItemTemplate> <DataTemplate > <StackPanel> <Image Name="imgSubCloud" Source="{Binding imgPath}" Stretch="None" Loaded="imgSubCloud_Loaded" ></Image> </StackPanel> <!--<Image Name="imgSubCloud1" Source="{Binding imgPath}" ></Image>--> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
</Grid>
List<Image> list = new List<Image>();
list.Add(new Image() { imgID = "1", imgName = "企鹅", imgPath = "../Pic/1.jpg" });
list.Add(new Image() { imgID = "2", imgName = "犀牛", imgPath = "../Pic/2.jpg" });
list.Add(new Image() { imgID = "3", imgName = "鹦鹉", imgPath = "../Pic/3.jpg" });
list.Add(new Image() { imgID = "4", imgName = "老虎", imgPath = "../Pic/4.jpg" });
list.Add(new Image() { imgID = "5", imgName = "蛤蟆", imgPath = "../Pic/5.jpg" });
list.Add(new Image() { imgID = "6", imgName = "小狗", imgPath = "../Pic/6.jpg" });
list.Add(new Image() { imgID = "7", imgName = "青蛙", imgPath = "../Pic/7.jpg" });
list.Add(new Image() { imgID = "8", imgName = "小龙", imgPath = "../Pic/8.jpg" });
list.Add(new Image() { imgID = "9", imgName = "乌龟", imgPath = "../Pic/9.jpg" });
list.Add(new Image() { imgID = "10", imgName = "茶杯", imgPath = "../Pic/10.jpg" });
ImgListBox.ItemsSource = list;
@菜鸟_001: 不用new Image() { imgID = "1", imgName = "企鹅", imgPath = "../Pic/1.jpg" } 了吧!
你可以直接 List<ImageEntity> list = new list<ImageEntity>();
ImageEntity ie=new ImageEntity();
ie.imageId="1";
ie.imagePath="/pic/1.jpg";
ie.imageName="企鹅"
list.add(ie)
上面的如果是个集合,那你放到for(){}
this.ImgListBox.ItemsSource = list;
@Beyond-bit: 这个我知道,但是怎么把显示的图片变成两行呢,图片的显示默认是一行。
@菜鸟_001: new Image()中的Image是我定义的一个类,不好意思图片显示成两列,默认是一列
@菜鸟_001: 不好意思、我有点不明白你的意思、
@Beyond-bit: 你的邮箱是多少,我把要显示的结果以图片的形式发给你
@菜鸟_001: 好吧,那我也不一定能帮你解决哦、shandowsoftware@126.com
@菜鸟_001: 哈哈哈,哥们,我明白了,我找到一个解决方案 了、可以用WrapPanel
给你几个链接参考你就知道了:http://bbs.csdn.net/topics/380190291
具体解决方法:http://blog.sina.com.cn/s/blog_4adf31ea0100mer7.html
@菜鸟_001: 代码:
<ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <toolkit:WrapPanel ItemWidth="100" ItemHeight="50"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBoxItem Content="Item1"/> <ListBoxItem Content="Item2"/> <ListBoxItem Content="Item3"/> <ListBoxItem Content="Item4"/> <ListBoxItem Content="Item5"/> <ListBoxItem Content="Item6"/> </ListBox>
通过:WrapPanel可以控制了、