无法在代码隐藏中访问我的ListView

时间:2017-06-02 21:22:47

标签: c# xaml listview windows-phone-8.1

我在XAML中有这段代码:

<Page
    x:Class="YenaWindowsMobile.View.Introduction"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:YenaWindowsMobile.View"
    xmlns:vm="using:YenaWindowsMobile.ViewModel"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid x:Name="PaginaInicio" Background="#243e51">
        <Grid.RowDefinitions>
            <RowDefinition Height="18"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.Resources>
            <vm:CompanyCollection x:Key="CompanyData"/>
        </Grid.Resources>
        <Hub x:Name="Hub1" Grid.Row="1">
            <HubSection x:Name="Marcas" Header="Marcas">
                <DataTemplate>
                    <ListView x:Name="listViewCompany" 
                              ItemsSource="{Binding Source={StaticResource CompanyData},Path=CompanyList}" 
                              IsItemClickEnabled="True"
                              ItemClick="ListView_ItemClick">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <Image Source="{Binding URL}" 
                                           Stretch="Uniform"
                                           CacheMode="BitmapCache"/>
                                    <TextBlock Text="{Binding Name}" 
                                               FontSize="28" 
                                               Margin="0,10,0,0"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </DataTemplate>
            </HubSection>
        </Hub>
    </Grid>
</Page>

...这是我的C#代码。我想取公司名称,但不能通过名称“listViewCompany”访问ListView,我不知道为什么。我不知道我做错了什么。

private async void listViewCompany_ItemClick(object sender, ItemClickEventArgs e)
{
    MessageDialog msgbox = new MessageDialog(listViewCompany.);
    await msgbox.ShowAsync();
}

0 个答案:

没有答案