【发布时间】:2011-09-20 06:38:39
【问题描述】:
我有一个列表框,我必须在所选项目上显示一个勾号。我试过这个代码
列表框
<ListBox Height="691" HorizontalAlignment="Left" Name="listBox1" Margin="-12,71,0,0" VerticalAlignment="Top" Width="480" SelectionChanged="listBox1_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0,1,0,0" BorderBrush="#FFC1BCBC" Width="490">
<Grid Height="70">
<TextBlock
Name="clients"
Margin="10,12,0,0"
Text="{Binding Name}" FontSize="24" FontWeight="SemiBold" Foreground="Black"></TextBlock>
<Image Height="30" Width="30"
HorizontalAlignment="Left"
Name="imageTick"
Stretch="Fill"
VerticalAlignment="Center"
Source="{Binding strAccountSelectedTickPath}"
Margin="380,0,0,0" Visibility="Collapsed"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
xaml.cs
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string clientId="";
if (listBox_1.SelectedIndex >= 0)
{
(Application.Current as App).obj_subnodes = newlist[listBox1.SelectedIndex];
if ((Application.Current as App).obj_subnodes.strAccountSelectedTickPath==""||(Application.Current as App).obj_subnodes.strAccountSelectedTickPath==null)
{
if ( (Application.Current as App).obj_subnodes.strAccountSelectedTickPath = "")
{
(Application.Current as App).obj_subnodes.strAccountSelectedTickPath = "/sprinklr;component/Images/IsSelected.png";}
else{ (Application.Current as App).obj_subnodes.strAccountSelectedTickPath = ""; }
initializeListBox();
}
NavigationService.Navigate(new Uri("/Home.xaml, UriKind.Relative));
}
}
private void initializeListBox()
{
listBox1.ItemsSource = "";
listBox1.ItemsSource = newlist;
}
但问题是假设如果我在列表框中有两个项目说 item1 和 item2 并且第一次我选择了 item1 并且勾选标记显示在 item1 上,之后我选择了项目 2 并且勾选标记显示在 item2 上。但是item1 上的刻度线没有消失。我必须显示一个刻度线来指示所选项目,即我希望刻度图像显示在我单击的项目上。有什么解决方案吗?是否有任何选项可以控制访问列表框中的刻度图像。如果有一个选项,我可以使用 imagetick.visibility=visibility.collapsed。但我没有找到这样的选项。有什么解决方案请帮助我
【问题讨论】:
标签: c# windows-phone-7 listbox