Windows phone 7 如何在windows Phone ListBox.ItemTemplate全景应用程序中获取项目单击事件(选择了哪个项目)
如何在windows Phone ListBox.ItemTemplate中获取选定/触摸项目详细信息 以下是内置模板的代码Windows phone 7 如何在windows Phone ListBox.ItemTemplate全景应用程序中获取项目单击事件(选择了哪个项目),windows-phone-7,windows-phone-8,windows-phone,Windows Phone 7,Windows Phone 8,Windows Phone,如何在windows Phone ListBox.ItemTemplate中获取选定/触摸项目详细信息 以下是内置模板的代码 <!--Panorama item one--> <controls:PanoramaItem Header="second item" Name="ptHeader1" > <!--Double line list with image placeholder and text wrapping-->
<!--Panorama item one-->
<controls:PanoramaItem Header="second item" Name="ptHeader1" >
<!--Double line list with image placeholder and text wrapping-->
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>
<StackPanel Width="311">
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
但是我无法获取所选项目的信息。当您像处理
ItemsSource=“{Binding Items}”那样对列表框进行数据绑定时,
SelectionChanged处理程序中的SelectedItem
属性包含其中一个项目,而不是ListBoxItem
试着这样做:
YourClass selectedItem = (sender as ListBox).SelectedItem as YourClass;
if(selectedItem != null)
{
var lineOne = selectedItem.LineOne;
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ptHeader1.Header = String.Format(" You selected {0}.", (sender as ListBox).SelectedText);
}
使用此代码选择
列表框
项:
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItemType lbi = ListBox.SelectedItem as ListBoxItemType;
}
我会这样做:
YourClass selectedItem = (sender as ListBox).SelectedItem as YourClass;
if(selectedItem != null)
{
var lineOne = selectedItem.LineOne;
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ptHeader1.Header = String.Format(" You selected {0}.", (sender as ListBox).SelectedText);
}
这里:几乎是相同的问题。请更新您的问题,为您在列表框上绑定的对象添加类