【问题标题】:ListView Tapped removes button background color on data template Xamarin.FormsListView Tapped 删除数据模板 Xamarin.Forms 上的按钮背景颜色
【发布时间】:2016-12-12 09:11:39
【问题描述】:

我不知道为什么,但是当我点击任何 ListView 项目时,其模板内的 Button 会失去背景颜色。

我在ListView 中使用默认的ViewCell。这是 Xamarin.Forms 错误吗?

我只在 iOS 上遇到这个问题。

    <ListView x:Name="lv" Grid.Row="2" HasUnevenRows="true" BackgroundColor="White" ItemTapped="OnItemTapped">
 <ListView.ItemTemplate>
      <DataTemplate>
       <ViewCell>               
       <StackLayout Padding="16" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="{Binding .,Converter={StaticResource IndexColorConverter}">

        <StackLayout VerticalOptions="Center">
                  <Label Text="{Binding Auditorium}" FontSize="18" TextColor="Black"/>
                  <ContentView Padding="0,-5,0,0">
                         <Label Text="{Binding Title}" FontSize="16" TextColor="Black"/>        
                  </ContentView>
      <StackLayout Orientation="Horizontal">
         <Button WidthRequest="100" Text="{Binding ButtonOverviewText}" TextColor="White" BackgroundColor="{Binding ButtonColor}" CommandParameter="{Binding .}" Clicked="Handle_Clicked"/>
         <Button WidthRequest="100" Text="{Binding ButtonOverviewText}" TextColor="White" BackgroundColor="{Binding ButtonColor}" CommandParameter="{Binding .}" Clicked="Handle_Clicked" />
   </StackLayout>
  </StackLayout>

   <Label Text="{Binding Coordinator}" FontSize="14" TextColor="Gray"/>

   </StackLayout>
   </ViewCell>
  </DataTemplate>
</ListView.ItemTemplate>
</ListView>

【问题讨论】:

    标签: c# ios xaml xamarin xamarin.forms


    【解决方案1】:

    有一个旧问题,我为类似的错误提交了:https://bugzilla.xamarin.com/show_bug.cgi?id=27502

    但是,您提到的特定场景是 iOS 上的预期行为,并且也发生在本机(非 Xamarin.Forms)项目中。见评论here。您可以考虑使用UITableViewCellSelectionStyle.None 禁用单元格的UITableViewCellSelectionStyleHere 是单元格渲染器的示例。您可以在此处设置cell.SelectionStyle。这将停止单元格的灰色突出显示。如果您不希望这样,保留按钮颜色可能是一种解决方法。

    【讨论】:

      【解决方案2】:

      我对这个问题的解决方法如下。

      <Grid>
      <BoxView BackgroundColor="{Binding ButtonColor}"/>
      <Button Text="{Binding ButtonOverviewText}" TextColor="White" BackgroundColor="Transparent" CommandParameter="{Binding .}" Clicked="Handle_Clicked"/>
      </Grid>
      

      【讨论】:

        猜你喜欢
        • 2019-07-22
        • 2014-11-03
        • 2011-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-24
        • 2017-03-25
        • 1970-01-01
        相关资源
        最近更新 更多