C# 如何在代码隐藏中恢复列表框中的textblock值?

C# 如何在代码隐藏中恢复列表框中的textblock值?,c#,.net,windows-phone-8,C#,.net,Windows Phone 8,我将恢复代码隐藏中文本块中的ItemId值 <phone:PanoramaItem Header="Available"> <Grid> <ListBox x:Name="ItemsCheckedinList" HorizontalAlignment="Left"> <ListBox.ItemsPanel>

我将恢复代码隐藏中文本块中的
ItemId

<phone:PanoramaItem Header="Available">
            <Grid>
                <ListBox x:Name="ItemsCheckedinList" HorizontalAlignment="Left">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Button x:Name="ButtonItemCheckedin" 
                Click="Button_ItemDetail" BorderBrush="{x:Null}" Width="200" 
                Height="200" Padding="0" Margin="0">
                                    <Button.Background>
                                        <ImageBrush ImageSource="{Binding Path=Image}" 
                Stretch="UniformToFill"/>
                                    </Button.Background>
                                    <StackPanel Orientation="Vertical" 
                Background="#FF0081C6" VerticalAlignment="Bottom" >
                                        <TextBlock Text="{Binding Path=Id}" 
                x:Name="ItemId" Visibility="Collapsed"/>
                                        <TextBlock Text="{Binding Path=Name}"/>
                                        <TextBlock Text="{Binding Path=Status}"/>
                                    </StackPanel>
                                </Button>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </phone:PanoramaItem>

您真正想要做的可能是从id最初来自的模型中获取值。假设列表中包含的类名为
Item
,可能是这样的

    private void Button_ItemDetail(object sender, RoutedEventArgs e)
        var fe = (FrameworkElement)sender;
        var item = (Item)fe.DataContext;
        var id = item.Id; // <-------------- id is in the variable id
    }
private void按钮\u ItemDetail(对象发送方,路由目标)
var fe=(FrameworkElement)发送方;
var item=(item)fe.DataContext;
var id=item.id//
    private void Button_ItemDetail(object sender, RoutedEventArgs e)
    {
        Button b = (Button)sender;
        var tb = (TextBlock)b.FindName("IdTextBox");
        var id = tb.Text; // <-------------- id is in the variable id
    }