0

I have this code in 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>

…and this is my C# code. I want to take the name of the company but can't access ListView by its name "listViewCompany" and I don´t know why. I don´t know what I´m doing wrong.

private async void listViewCompany_ItemClick(object sender, ItemClickEventArgs e)
{
    MessageDialog msgbox = new MessageDialog(listViewCompany.);
    await msgbox.ShowAsync();
}
Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
okami mac
  • 23
  • 3
  • Fields are generated for named elements only for those elements that exist statically in the XAML. Templates are dynamic, created on an as-needed basis. You won't find a generated field for named elements inside templates. See marked duplicates for some of the techniques you may use. It's not clear why you are declaring the template directly there, nor why you want that element to be passed to the `MessageDialog()` method, but you should be able to use those techniques to get what you want. Consider, however, alternatives to your implementation that don't require that at all. – Peter Duniho Jun 02 '17 at 21:39
  • Thanks @PeterDuniho, – okami mac Jun 05 '17 at 14:00

0 Answers0