Xamarin表单 - 删除额外的空间/嵌入式ListView

时间:2017-01-13 21:58:05

标签: xamarin xamarin.forms

我想弄清楚如何移除下图中看到的空白区域(被红色矩形包围)。注意我有一个嵌入在父ListView中的ListView。

enter image description here

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>

这可能不是必需的,但这是模型......

MODEL

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"); } }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

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