How to access controls of the xaml that are inside from a ListView ?

Andreeh_AraujoAndreeh_Araujo ✭✭BRMember ✭✭

I need to declare values to the properties to the controls that build my view in code behind (.cs), but this controls are inside from a ListView and i don't know access.

I already tried:

var lblLogradouro= this.FindByName<Label>("lblLogradouro");

But the Compiling don't know find this control.

My xaml:

    <ListView x:Name="lvEnderecos" RowHeight="210">
            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>

                  <Grid x:Name="GridControl" RowSpacing="0" ColumnSpacing="0">
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*"/>
                      <RowDefinition Height="20"/>

                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                    </Grid.ColumnDefinitions>
                    <StackLayout x:Name="stkEnderecos" BackgroundColor="White" Padding="0, 0, 0, 0" Grid.Row="0">

                      <Label x:Name="lblNomeDestinatario" Text=" {Binding EndDestinatario}" Font="16" TextColor="Black"></Label>
                      <Label x:Name="lblTipoEndereco" Text=" {Binding EndTipo, StringFormat='({0})'}" Font="16" TextColor="Black"></Label>
                      <Label Text="  _________________________________________________ " TextColor="Black"></Label>
                      <Grid x:Name="GridControl2" RowSpacing="0" ColumnSpacing="0">
                        <Grid.RowDefinitions>
                          <RowDefinition Height="25"/>
                          <RowDefinition Height="25"/>
                          <RowDefinition Height="25"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto" />
                          <ColumnDefinition Width="Auto" />
                          <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label x:Name="lblLogradouro" Font="14" TextColor="Black" Text="{Binding EndLogradouro}" Grid.Row="0" Grid.Column="0"></Label>
                        <Label x:Name="lblNumero" Font="14" TextColor="Black" Text="{Binding EndNumero}" Grid.Row="0" Grid.Column="1"></Label>
                        <Label x:Name="lblComplemento" Font="14" TextColor="Black" Text="{Binding EndComplemento}" Grid.Row="0" Grid.Column="2"></Label>
                        <Label x:Name="lblBairro" Font="14" TextColor="Black" Text="{Binding EndBairro}" Grid.Row="1" Grid.Column="0"></Label>
                        <Label x:Name="lblCidade" Font="14" TextColor="Black" Text="{Binding EndCidade}" Grid.Row="1" Grid.Column="1"></Label>
                        <Label x:Name="lblUF" Font="14" TextColor="Black" Text="{Binding EndUF}" Grid.Row="1" Grid.Column="2"></Label>
                        <Label x:Name="lblCEP" Font="14" TextColor="Black" Text="{Binding EndCep, StringFormat='CEP: {0}'}" Grid.Row="2" Grid.ColumnSpan="2"></Label>
                      </Grid>
                      <Grid x:Name="GridControl3" RowSpacing="0" ColumnSpacing="5">
                        <Grid.RowDefinitions>
                          <RowDefinition Height="25"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto" />
                          <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <StackLayout x:Name="stkEditarEndereco" Grid.Row="0" Grid.Column="0" Padding="5, 0, 0, 0" HeightRequest="25" WidthRequest="25">
                          <Button x:Name="btnEditarEndereco" BackgroundColor="Transparent" Image="editar.png" HeightRequest="25" WidthRequest="25" 
                                  Command="{Binding Path=BindingContext.EditarEnderecoCommand, Source={x:Reference MeusEnderecosView}}" CommandParameter="{Binding .}" />
                        </StackLayout>
                        <StackLayout x:Name="stkExcluirEndereco" Grid.Row="0" Grid.Column="1" Padding="5, 0, 0, 0" HeightRequest="25" WidthRequest="25">
                         <Button x:Name="btnExcluirEndereco" BackgroundColor="Transparent" Image="excluir1.png" HeightRequest="25" WidthRequest="25"
                                  Command="{Binding Path=BindingContext.ExcluirEnderecoCommand, Source={x:Reference MeusEnderecosView}}" CommandParameter="{Binding .}" />
                        </StackLayout>
                      </Grid>
                    </StackLayout>
                  </Grid>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>

How to i can do it ?

Best Answer

Answers

Sign In or Register to comment.