【问题标题】:Xamarin forms: Entire row highlighting when tapped FlowListView item?Xamarin 表单:点击 FlowListView 项目时整行突出显示?
【发布时间】:2019-06-12 12:09:57
【问题描述】:

我在我的项目中添加了 FlowListView。正如FAQ 中提到的那样我在点击windows 中的一项时面临整行突出显示问题,android 中没有这样的问题。我添加了如下自定义渲染器:

在主项目中:

using DLToolkit.Forms.Controls;

namespace Mynamespace
{
    public class CustomFlowListView : FlowListView
    {
    }
}

在 UWP 中:

using Listpm;
using Listpm.UWP;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;

[assembly: ExportRenderer(typeof(CustomFlowListView), typeof(CustomListViewRenderer))]

namespace Listpm.UWP
{
    class CustomListViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);

            if (List != null)
                List.SelectionMode = Windows.UI.Xaml.Controls.ListViewSelectionMode.None;
        }
    }
}

在 xaml 中添加了 &lt;local:CustomFlowListView&gt; 而不是 &lt;flv:FlowListView&gt;

<local:CustomFlowListView
     FlowColumnCount="2" 
     SeparatorVisibility="None" 
     HasUnevenRows="false"
     RowHeight="200"
     FlowItemsSource="{Binding AllItems}">
     <flv:FlowListView.FlowColumnTemplate>
       <DataTemplate>
          <StackLayout
             HorizontalOptions="FillAndExpand"
             VerticalOptions="FillAndExpand"> 
              <Image/>
             </StackLayout>
        </DataTemplate>
     </flv:FlowListView.FlowColumnTemplate>
  </local:CustomFlowListView>

是否有任何其他更改来解决此问题?

【问题讨论】:

  • List.SelectionMode = Windows.UI.Xaml.Controls.ListViewSelectionMode.None; 将禁用 ListView 行突出显示。那么你想要什么行为呢?
  • 请尝试使用此行List.SelectionMode = Windows.UI.Xaml.Controls.ListViewSelectionMode.Single
  • @NicoZhu-MSFT 不走运,单击一个项目时整行都会突出显示。
  • 请尝试在您的渲染中添加行List.IsItemClickEnabled = false;

标签: xamarin.forms uwp custom-renderer


【解决方案1】:

如何在点击时禁用整行突出显示?

您还需要添加List.IsItemClickEnabled = false。它不会影响FlowItemTapped 事件。 受保护的覆盖无效

OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
    base.OnElementChanged(e);

    if (List != null)
        List.SelectionMode = Windows.UI.Xaml.Controls.ListViewSelectionMode.None;
        List.IsItemClickEnabled = false;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 2017-09-21
    相关资源
    最近更新 更多