我想拉伸一个类似的列表框:
<Grid Background="#FFC0BBBB">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border HorizontalAlignment="Stretch" Grid.Row="0">
<ListBox Name="listBox" >
<ListBoxItem >
<StackPanel>
<TextBlock Text="Toto"></TextBlock>
<!--<Image Source ="" Visibility="Collapsed" />-->
</StackPanel>
</ListBoxItem>
<ListBoxItem >listbox item 2</ListBoxItem>
<ListBoxItem >
<Grid>
<TextBlock Text="Tata"></TextBlock>
<Image Source ="" />
</Grid>
</ListBoxItem>
<ListBoxItem >
<Grid>
<TextBlock Background="Aqua" Text=""></TextBlock>
<Image Source ="https://support.twitter.com/images/twitter-bird.png?1339467554" />
</Grid>
</ListBoxItem>
<ListBoxItem >
<Grid>
<TextBlock Text="Vava"></TextBlock>
<Image Source ="" />
</Grid>
</ListBoxItem>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" Background="Pink" HorizontalAlignment="Stretch" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Border>
</Grid>
如果你只是为第二个项目添加内容它完美,但我的“真正的”ListBox将绑定,对于一些项目,我需要为其他人放一个图像TextBlock(我需要图像文本块) . 我认为我将不得不使用转换器,但我不知道“放在哪里”以及它应该返回什么 .
有任何想法吗 ?谢谢
1 回答
如果您绑定数据,然后使用数据属性来确定
ListBoxItem
中需要哪种控件,那么您需要使用DataTemplateSelector
http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx