如何在xamarin.forms中获取ListView的子代码?

时间:2016-11-18 05:33:28

标签: c# xamarin xamarin.ios xamarin.android xamarin.forms

<ListView x:Name="ListNewsLetter"  AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"  SeparatorVisibility="Default" VerticalOptions="Fill" ItemTapped="ListNewsLetter_ItemTapped" HasUnevenRows="True">
          <ListView.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <ViewCell.View>
                  <StackLayout HorizontalOptions="Fill" VerticalOptions="Center" Padding="5">
                    <StackLayout Padding="1" BackgroundColor="#f15a23" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                      <StackLayout x:Name="stkNewsLetter" VerticalOptions="Center" BackgroundColor="#f15a23" Orientation="Horizontal" HeightRequest="30" Padding="6,0,6,0">
                        <Label x:Name="lblName" Text="{Binding NewsHeadline}" HorizontalOptions="StartAndExpand" TextColor="White" VerticalTextAlignment="Center" FontSize="Small"/>
                        <Image x:Name="imgPlus_Minus" HeightRequest="20" WidthRequest="20" Source="ico_down_arrow2_right.png" HorizontalOptions="End" ClassId="{Binding TapId}">
                          <Image.GestureRecognizers>
                            <TapGestureRecognizer Tapped="img_Tapped" NumberOfTapsRequired="1" />
                          </Image.GestureRecognizers>
                        </Image>
                      </StackLayout>
                      <StackLayout x:Name="stkNewsLetterDetail" Orientation="Vertical" BackgroundColor="#ffffff" IsVisible="true" HorizontalOptions="FillAndExpand" Padding="6,0,6,0">
                        <Label x:Name="lblDate" Text="{Binding NewsDate}" HorizontalOptions="StartAndExpand" VerticalTextAlignment="Start" TextColor="#585858" FontSize="Small"/>
                        <Label x:Name="lblDetail" Text="{Binding NewsDetails}" HorizontalOptions="FillAndExpand" VerticalTextAlignment="Start" TextColor="#585858" FontSize="Small"/>
                      </StackLayout>
                    </StackLayout>
                  </StackLayout>
                </ViewCell.View>
              </ViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>

正如您在代码ListView中看到的那样,主要有两个名为&#34; stkNewsLetter&#34;和&#34; stkNewLetterDetail&#34;。第一个堆栈有图像,我想改变图像点击事件的第二个堆栈的可见性。

在Windows手机中可以获取列表视图的UI元素,但在xamarin.forms中如何实现?

1 个答案:

答案 0 :(得分:2)

您应该像绑定Text一样绑定到stackLayout上的Visability属性。如果stackLayout没有可见性属性,您可能需要将其包装在另一个控件中。

点击应该更改viewmodel中的可见性属性,该属性将被上面提到的绑定拾取。