【问题标题】:Xamarin forms: hide listview GroupHeaderXamarin 表单:隐藏列表视图 GroupHeader
【发布时间】:2017-02-09 04:55:25
【问题描述】:

有没有办法在 Xamarin 表单中隐藏列表视图的组标题? 我尝试在模板中设置标题高度,但它不起作用:

  <ListView ItemsSource="{Binding GroupedMenuItems}" SelectedItem="{Binding SelectedMenuItem}" SeparatorVisibility="None" IsGroupingEnabled="true">
          <ListView.GroupHeaderTemplate>
            <DataTemplate>
              <ViewCell Height="1">
              </ViewCell>
            </DataTemplate>
          </ListView.GroupHeaderTemplate>
          <ListView.ItemTemplate>
            <DataTemplate>
              <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" TextColor="#000000"/>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>

我只想在组之间显示分隔符。

【问题讨论】:

    标签: listview xamarin header xamarin.forms


    【解决方案1】:

    是的!您需要在 ListView 上将 HasUnevenRows 设置为 true。然后将标题模板设置为ViewCell,高度为0,带有空网格或其他元素。

     <ListView ItemsSource="{Binding GroupedMenuItems}" SelectedItem="{Binding SelectedMenuItem}" SeparatorVisibility="None" IsGroupingEnabled="true" HasUnevenRows="True">
          <ListView.GroupHeaderTemplate>
            <DataTemplate>
              <ViewCell Height="0">
                  <Grid/>
              </ViewCell>
            </DataTemplate>
          </ListView.GroupHeaderTemplate>
          <ListView.ItemTemplate>
            <DataTemplate>
              <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" TextColor="#000000"/>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
    

    【讨论】:

    • 谢谢!请注意,它不适用于 UWP。 (IOS没测试过,安卓没问题)。
    【解决方案2】:

    SuavePirate 的答案可能适用于 Android,但我需要稍作改动才能让它几乎可以在 iOS 上运行。我不得不将 ViewCell Height 从 0 更改为 1。我知道,这很奇怪,但是,无论出于何种原因,它都无法正常工作。

    有了这个小改动,仍然有一条 1 像素高的线将组彼此分开,这并不理想,但对于大多数用途来说已经足够了。我试图通过在 ViewCell 内放置一个 StackLayout 并将其 BackgroundColor 设置为“White”来隐藏该行。我还尝试在 Grid 中放置一个 BoxView 并将其颜色设置为“白色”,但这些方法都没有成功隐藏那条 1 像素高的线。

    哦,好吧,总比没有好。

    【讨论】:

    • 要隐藏该行,请将GridBackgroundColor 设置在ViewCell 内,而不是直接在ViewCell 上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多