我有在它的多个项目,如TextBlock的,图像等列表中...更改列表框项目可见
现在在XAML文件中所有项目的知名度将根据条件倒塌,在我.CS文件我决定要显示哪个项目,因为我需要仅显示TextBlock或Image,但由于默认情况下所有项目的可见性都已折叠,因此如何动态更改ListBoxItems可见性并将数据或图像设置为项目?
这里是我的XAML代码:
<ListBox Name="listBox"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
SelectionChanged="TopicListboxSelectionChanged"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="CellBack" Margin="0,0,0,4" Orientation="Horizontal">
<Border Name="borderColor" Background="#FFF2F4F7">
<TextBlock Name="text"
Width="456"
Padding="10,20,10,20"
Visibility="Collapsed"
TextAlignment="Center"
Text="{Binding Path=Value}"
Style="{StaticResource TextStyle}"/>
</Border>
<Image Name="Image"
Grid.Row="0"
Visibility="Collapsed"
Width="Auto"
Height="Auto"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="1,1,1,1"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
编辑
我paht在我.CS文件中的图像源是这样的:
image = "Path to my soucre" + imagename +"phone.png";
现在,在中XAML文件中的图像如何将此路径绑定到它?
通常我们做这样的:
BitmapImage bmp = new BitmapImage(new Uri(fileName, UriKind.Relative));
MyImage.Source = bmp;
这里MYIMAGE是在XAML文件映像的名称,但在我的情况下,我不能让图像名称是在列表框中,所以现在如何绑定数据?
你如何决定哪个控件是可见的,是否有'Data'与'DataContext'这个? – Sankarann
我有一个对象,我可以检查是否包含图像或文本基于我必须使文本块或图像显示或显示在屏幕上,但如何做到这一点? – Goofy
你的'对象'出现在哪里?在'ListItem'的'DataContext'中? – Sankarann