从代码隐藏的Xamarin表单中调用控件内部的对象

时间:2017-01-16 10:42:21

标签: c# xaml xamarin.forms controls code-behind

为什么我不能从代码隐藏中调用对象图像和对象图像 backClickArrow nextClickArrow ?他们不能,因为这些都在控制之内? 我如何从代码隐藏调用,他们需要启动一个事件?非常感谢你。

<control:CarouselView x:Name="carouselView">
            <control:CarouselView.ItemTemplate>
              <DataTemplate>
                <Grid Padding="10">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="40*"></RowDefinition>
                    <RowDefinition Height="0.2*"></RowDefinition>
                    <RowDefinition Height="59.8*"></RowDefinition>
                  </Grid.RowDefinitions>
                  <Grid Grid.Row="0">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="5*"></ColumnDefinition>
                      <ColumnDefinition Width="40*"></ColumnDefinition>
                      <ColumnDefinition Width="50*"></ColumnDefinition>
                      <ColumnDefinition Width="5*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Image Source="backBlueArrow.png" x:Name="backClickArrow" Aspect="AspectFit" Grid.Column="0"></Image>
                    <StackLayout Margin="0,0,10,0" VerticalOptions="Center" HorizontalOptions="End" Grid.Column="1">
                      <Image HeightRequest="70" Source="clock.png" Aspect="AspectFit"></Image>
                    </StackLayout>
                    <Grid Grid.Row="0" Grid.Column="2">
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                      </Grid.ColumnDefinitions>
                      <Grid.RowDefinitions>
                        <RowDefinition Height="40*"></RowDefinition>
                        <RowDefinition Height="60*"></RowDefinition>
                      </Grid.RowDefinitions>
                      <Label Text="Superficie totale" TextColor="#fff" FontSize="Small" VerticalTextAlignment="End" HorizontalTextAlignment="Start" Grid.Row="0"/>
                      <Label Text="890000m2" FontSize="Large" TextColor="#fff" VerticalTextAlignment="Start" HorizontalTextAlignment="Start" Grid.Row="1"/>
                    </Grid>
                    <Image Source="nextBlueArrow.png" x:Name="nextClickArrow" Aspect="AspectFit" Grid.Column="3"></Image>
                  </Grid>
                  <!-- griglia fare la riga bianca -->
                  <Grid Padding="0" BackgroundColor="White" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                  </Grid>
                  <Grid Padding="10" Grid.Row="2">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                  </Grid>

              </Grid>
      <!--<Label Text="{Binding Testo}" />-->
      </DataTemplate>
      </control:CarouselView.ItemTemplate>
      </control:CarouselView>

我希望打电话的对象:

<Image Source="backBlueArrow.png" x:Name="backClickArrow" Aspect="AspectFit" Grid.Column="0"></Image>

<Image Source="nextBlueArrow.png" x:Name="nextClickArrow" Aspect="AspectFit" Grid.Column="3"></Image>

1 个答案:

答案 0 :(得分:0)

我已经解决了这样的问题:

<Button Image="nextBlueArrow.png" Clicked="clickme" Grid.Column="3"></Button>

使用按钮并添加图像属性。