0

this is my xaml:

    <ListView Name="myListView" ItemsSource="{Binding ElementName=IndexPage, Path=SeriesCollection}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" IsSynchronizedWithCurrentItem="True" SelectionChanged="handleSelected">
    <ListView.ItemsPanel >
        <ItemsPanelTemplate>
            <WrapPanel>
            </WrapPanel>
        </ItemsPanelTemplate>            
    </ListView.ItemsPanel>
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel >
                <Image Width="214" Height="317" Source="{Binding Image}"/>
                <Label Content="{Binding Name}" />
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

and this is my code behind

    public void handleSelected(object sender, RoutedEventArgs args)
    {
        object currentSerie = myListView.Items.CurrentItem;
        Console.WriteLine(currentSerie.GetType());
        Console.WriteLine(currentSerie.ToString());
    }

how do i work with currentSerie? how do i access the data which is stored in each Item? i cant access properties and i cant convert it to anything else then object.

also interesting, the output of the code is not "object" but "Series" so ToString() and GetType() gets the type right.

thx for any help

4

3 回答 3

0

You are casting to object so you only get the properties of object. Cast is to a the real custom class and you will get the properties of that class. myClass currentSer =

于 2012-04-03T16:07:44.817 回答
0

Simply cast currentSerie to type Series.

Series currentSerie = (Series)myListView.Items.CurrentItem;
于 2012-04-03T16:08:11.503 回答
0

How about casting it?

Series series = (Series)myListView.Items.CurrentItem;
于 2012-04-03T16:08:19.643 回答