0

我有一个TabbedPage并且我打算做的是将一个 json 流式传输ListViewContentPageMainPage 下的一个。

据我所知,当翻译成 xaml 时,丢失的地方就出现了。

谁能帮我解决这个问题?

我的代码如下所示:

我的 C# 文件

void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs eventInfo)
{
    if (eventInfo.SelectedItem != null)
    {
        cityItem clickedCityName = (cityItem)eventInfo.SelectedItem;

        System.Diagnostics.Debug.WriteLine(clickedCityName.cityAddress);
        citiesListView.SelectedItem = null;

        SingelCityPage pcity = new SingelCityPage ();
        pcity.currentCity = clickedCityName;

        //Looks like I am missing something here but I don't find any reference.
        //or is in the XML that its missing the connection? 
        Navigation.PushAsync(pcity);
        }
    }

我的 Xaml

<ContentPage.Content>
    <StackLayout>
        <ListView x:Name="citiesListView">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                          <ViewCell.ContextActions>
                                <AbsoluteLayout Padding="10,10,10,10">
                                    <Label Text="{Binding cityName}" AbsoluteLayout.LayoutBounds="0.0, 0.0, 0.75, 0.5" AbsoluteLayout.LayoutFlags="All" />
                                    <Label Text="{Binding cityLocation}" AbsoluteLayout.LayoutBounds="0.0, 1.0, 0.75, 0.5" AbsoluteLayout.LayoutFlags="All" />
                                    <Label Text="{Binding cityAdress}" AbsoluteLayout.LayoutBounds="1.0, 0.0, 0.5, 1.0" AbsoluteLayout.LayoutFlags="All" />
                                </AbsoluteLayout>
                          </ViewCell.ContextActions>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView> 
    </StackLayout>
</ContentPage.Content>
4

1 回答 1

0

在您的代码库中,您(至少)有 2 个MyListItem在不同命名空间中命名的类。一个可能是由 json 反序列化自动生成的,我只能在这里猜测。

即使它们具有相同的名称,它们也是不同的类,并且不能将一个实例转换为另一个实例。

确保在任何地方都使用相同的类型。

再次猜测,因为粘贴的片段没有帮助,我会说问题发生在这一行:

pcity.currentCity = clickedCityName;
于 2016-10-12T06:51:13.470 回答