【问题标题】:Xamarin Forms - remove extra space / embedded ListViewXamarin Forms - 删除额外空间/嵌入式 ListView
【发布时间】:2017-01-14 11:03:35
【问题描述】:

我正在尝试弄清楚如何删除您在下图中看到的空白(被红色矩形包围)。请注意,我在父 ListView 中嵌入了一个 ListView。

XAML

<ListView x:Name="___listview" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <Button Image="{Binding ImageName}" Command="{Binding ShowDetailsCommand}" />
                    <ListView ItemsSource="{Binding Notes}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <TextCell Text="{Binding Note}" />
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

这可能不需要,但这是模型......

型号

namespace ViewCellClick
{
    public class ModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class Model : ModelBase
    {
        public Model()
        {
            _imageName = "ellipses_vertical.png";
            _showDetails = true;
            ShowDetailsCommand = new Command(() =>
            {
                ShowDetails = !_showDetails;
                ImageName = (_imageName == "ellipses_vertical.png")
                                        ? "ellipses_horizontal.png"
                                        : "ellipses_vertical.png";
            });
        }

        bool _showDetails;
        public bool ShowDetails
        {
            get { return _showDetails; }
            set { if (_showDetails != value) { _showDetails = value; OnPropertyChanged("ShowDetails"); } }
        }

        string _imageName;
        public string ImageName
        {
            get { return _imageName; }
            set { if (_imageName != value) { _imageName = value; OnPropertyChanged("ImageName"); } }
        }

        public ICommand ShowDetailsCommand { get; set; }

        List<ChildModel> _notes;
        public List<ChildModel> Notes { get { return _notes; } set { _notes = value; } }
    }

    public class ChildModel : ModelBase
    {
        public ChildModel(string note) { _note = note; }
        string _note;
        public string Note
        {
            get { return _note; }
            set { if (_note != value) { _note = value; OnPropertyChanged("Note"); } }
        }
    }
}

【问题讨论】:

  • Xamarin Forms 不支持 ListView 中的 ListView,并且已经讨论过 here

标签: xamarin xamarin.forms


【解决方案1】:

您不能使用 Xamarin.Forms.ListView 执行此操作,并且不支持嵌套它们。真的在 iOS 上,这将是非常困难的,我不确定如果没有一些奇怪的手势行为,你是否可以让它工作。

【讨论】:

  • 我能够以不同的方式实现这一点。基本上该技术是扩展 ViewCell。在构造函数中,我创建了一个 StackLayout 并将其设置为 View。在 OnAppearing 中,我使用 C# 创建控件,并且可以循环遍历内部列表来构建我尝试使用嵌入式 ListView 完成的相同操作。
  • 你能告诉我你是怎么做到的吗?
猜你喜欢
  • 2018-08-20
  • 2019-08-09
  • 2020-04-15
  • 2021-10-27
  • 2018-03-19
  • 1970-01-01
  • 2020-10-16
  • 1970-01-01
相关资源
最近更新 更多