-1

这是我要提取享受ID的图像

我要提取的内部数据细节

我想从数据有界的选定项目中提取享受ID,但由于invalidCastException,我尝试了web中可用的所有方法仍然无法提取它。

    private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        SuperData data = (sender as ListBox).SelectedItem as SuperData;
        ListBoxItem selected = this.listBox1.ItemContainerGenerator.ContainerFromItem(data) as ListBoxItem;
    }

我试过这个和 e.AddedItem[0] 但仍然无法得到它。

<Grid>
                <ListBox HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="listBox1" VerticalAlignment="Stretch" SelectionChanged="listBox1_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Height="132">
                                <Image Source="{Binding image}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
                                <StackPanel Width="370">
                                    <TextBlock Text="{Binding title}" Foreground="#FFC8AB14" FontSize="28" />
                                    <!--TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" /-->
                                    <TextBlock Text="{Binding description}" TextWrapping="Wrap" FontSize="24" />
                                    <TextBlock Text="Test" TextWrapping="Wrap" FontSize="24" />
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>

这是我绑定数据的 UI 部分。WCF 的返回是List<REData>数据类型,我只是用 . 绑定到列表框listBox1.ItemsSource = e.Result

    public int category { get; set; }
    public int categoryField { get; set; }
    public string description { get; set; }
    public string descriptionField { get; set; }
    public int enjoymentID { get; set; }
    public int enjoymentIDField { get; set; }
    public string image { get; set; }
    public string imageField { get; set; }
    public object PropertyChanged { get; set; } << i don't know what is this
    public string title { get; set; }
    public string titleField { get; set; }

这也是 e.AddedItem[0] 中的内容:

在此处输入图像描述

4

1 回答 1

1

从您的屏幕截图中,数组第一项的类型是 RoyalEnjoyment.REServiceReference.REData,如果您将 e.AddedItems[0] 转换为这种类型,那么您应该能够访问各种属性值。

例如,RoyalEnjoyment.REServiceReference.REData x = (RoyalEnjoyment.REServiceReference.REData)e.AddedItems[0];

于 2012-05-15T13:46:24.550 回答