Xamarin.forms-自定义ViewCell中的BoxView

Xamarin.forms-自定义ViewCell中的BoxView,xamarin.forms,prism,Xamarin.forms,Prism,我想为包含stacklayout(grid+BoxView)的viewcell中定义的列表的最后一个元素将BoxView的VisibleProperty设置为false。有没有办法将其设为false,以便最后一个元素不包含boxview分隔线?解决方案: 您可以将bool属性isShow添加到viewModel中,并使用此属性控制boxView是否可见 public class MyViewModel { //use this property to control wh

我想为包含stacklayout(grid+BoxView)的viewcell中定义的列表的最后一个元素将BoxView的VisibleProperty设置为false。有没有办法将其设为false,以便最后一个元素不包含boxview分隔线?

解决方案:

您可以将bool属性
isShow
添加到viewModel中,并使用此属性控制boxView是否可见

public class MyViewModel
    {
        //use this property to control whether the boxView is visible
        public bool isShow { get; set; }
    }
然后通过
boxOne.SetBinding(boxView.IsVisibleProperty,新绑定(“isShow”))将此属性绑定到customCell中的
boxView

最后,在创建
MyViewModel
的新实例时,可以设置
isShow
属性
true/false
,以控制
boxView
是否在单元格中可见

    public MainViewCode()
    {
        myCollection = new ObservableCollection<MyViewModel>();
        ListView lstView = new ListView();  
        lstView.ItemTemplate = new DataTemplate(typeof(CustomCell));

        myCollection.Add(new MyViewModel { isShow = true });
        myCollection.Add(new MyViewModel { isShow = false });
        lstView.ItemsSource = myCollection;

        Content = lstView;
    }
public主视图代码()
{
myCollection=新的ObservableCollection();
ListView lstView=新建ListView();
lstView.ItemTemplate=新数据模板(typeof(CustomCell));
添加(新的MyViewModel{isShow=true});
添加(新的MyViewModel{isShow=false});
lstView.ItemsSource=myCollection;
内容=视图;
}
    public MainViewCode()
    {
        myCollection = new ObservableCollection<MyViewModel>();
        ListView lstView = new ListView();  
        lstView.ItemTemplate = new DataTemplate(typeof(CustomCell));

        myCollection.Add(new MyViewModel { isShow = true });
        myCollection.Add(new MyViewModel { isShow = false });
        lstView.ItemsSource = myCollection;

        Content = lstView;
    }