【问题标题】:How to disable ViewCell but keep enabled Grid inside it?如何禁用 ViewCell 但在其中保留启用的 Grid?
【发布时间】:2019-04-24 10:25:38
【问题描述】:

我在 xaml 文件中有这样的结构:

<ListView>
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Frame>
                    <Grid>
                        <Grid.GestureRecognizers>
                            <TapGestureRecognizer/>
                        </Grid.GestureRecognizers>
                    </Grid>
                </Frame>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

如何因为选中项的默认橙色背景颜色而禁用单击 ListView,但保持启用的 Grid?

【问题讨论】:

    标签: listview xamarin.forms grid gesture-recognition


    【解决方案1】:

    可以使用ListView.SelectionMode 属性来完成:
    SelectionMode = ListViewSelectionMode.None;

    官方文档可以在here找到。

    【讨论】:

    • 嗯,这很重要... :D 但是背景上仍然存在一些“闪烁”效果。它是灰色透明的。没什么大不了的,但有什么解决方案可以禁用它吗?
    • 闪烁出现在哪个平台上?
    • 在安卓平台上。
    【解决方案2】:

    在您的 Android 项目中添加以下代码

    在资源中-->值-->style.xml

    <item name="android:selectableItemBackground">@null</item>
    
    <item name="android:selectableItemBackgroundBorderless">@null</item>
    
    <item name="android:colorControlHighlight">@android:color/transparent</item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 2017-11-14
      • 1970-01-01
      相关资源
      最近更新 更多