问题描述
本人刚接触wpf,菜鸟一枚,求各路大神指教:后台相应代码:publicCurriculumsView(){InitializeComponent();viewModel=newMainWindowViewModel();}前台相应代码:<ListView.View><GridView><GridViewColumnWidth="120"DisplayMemberBinding="{BindingPath=type}"Header="分类"/><GridViewColumnWidth="250"DisplayMemberBinding="{BindingPath=content}"Header="内容"/></GridView></ListView.View>其中type和content是mainViewModel中包含的CurriculumViewModel中的实体类Curriculum的属性
解决方案
解决方案二:
你没写listview的绑定,在前台绑定<ListView.Viewitemssource="{BindingviewModel}">或者在后台绑定,现在前台给Listview取个名字<ListView.Viewname="lv">,然后在后台的publicCurriculumsView(){InitializeComponent();viewModel=newMainWindowViewModel();}中加入lv.itemssource=viewModel,即效果是{InitializeComponent();viewModel=newMainWindowViewModel();lv.itemssource=viewModel}望采纳
解决方案三:
抱歉哈,之前忘记粘贴绑定了,我已经绑定过了,所以你说的不是我现在不清楚的问题,不过还是谢谢你。publicCurriculumsView(){InitializeComponent();viewModel=newMainWindowViewModel();this.DataContext=viewModel;}
解决方案四:
木有大神路过吗?自顶