【发布时间】:2015-01-21 05:14:51
【问题描述】:
我正在使用 listboxselection mode=multiple 选择多个列表框条目,而不是在按钮单击事件上,我正在尝试/想要使用 for-each 循环获取 txtID 文本值,并为每个选定的项目显示带有打印在其中的 id 的消息框。 我的列表框语法如下
<ListBox Grid.Row="1" Name="lstAnnouncement" SelectionMode="Multiple" Width="476" d:LayoutOverrides="VerticalMargin">
<ListBox.ItemTemplate >
<DataTemplate>
<StackPanel Name="thispanel" Grid.Row="1" Orientation="Horizontal" Height="120" Width="478" >
<StackPanel.Background>
<ImageBrush ImageSource="Images/Text-ALU.png" Stretch="Fill" />
<!--<SolidColorBrush Color="{Binding Path=background}"/>-->
</StackPanel.Background>
<Grid HorizontalAlignment="Left" Width="30" Margin="0,0,0,2" Background="#FF0195D5" Height="118">
<!--<Grid.Background>
<ImageBrush ImageSource="Images/Text-ALU.png" Stretch="Fill" />
</Grid.Background>-->
</Grid>
<Grid HorizontalAlignment="Left" Width="5" Height="120"/>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Width="432" Height="114">
<StackPanel Orientation="Horizontal" Width="432" Height="27">
</StackPanel>
<StackPanel Orientation="Horizontal" Width="433" Height="60">
<TextBlock x:Name="txtID" Height="56" Text="{Binding Path=announcementID}" TextWrapping="Wrap" Foreground="Black" FontSize="18.667" Width="8" Visibility="Collapsed"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
点击事件的代码隐藏如下
foreach (var listBoxItem in lstAnnouncement.SelectedItems)
{
messegebox.show(txtId.text);
// but this(txtID) is not accessible as it is in datatemplete
//so how to achieve the same
}
【问题讨论】:
标签: c# windows-phone-8 foreach listbox