有谁知道为什么我的 ListView 以下代码不起作用?我用 Snoop 进行了检查,ItemsSource 似乎很好(当我启动 Snoop 时,ListView 向我显示 MyViewModel.MyCollection,但是在使用 Visual Studio 调试时它什么也没显示?)
谢谢!
PS:MainWindow.xaml.cs 有 DataContext = MainViewModel
<ListView Grid.Row="1" Margin="38,50,0,168" HorizontalAlignment="Left" Name="listViewSelectDate" Width="105"
ItemsSource="{Binding Path=MyViewModel.MyCollection}"
SelectedItem="{Binding SelectedDate}" IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" DisplayMemberBinding="{Binding Path=CalcDate}"/>
</GridView>
</ListView.View>
</ListView>
ViewModel 看起来像这样:
class MainViewModel : ViewModelBase
{
public SummaryViewModel MyViewModel
{
get { return _myViewModel; }
set { _myViewModel = value; RaisePropertyChanged("MyViewModel"); }
}
public MyDate SelectedDate
{
get { return _selectedDate; }
set { _selectedDate = value; RaisePropertyChanged("SelectedDate"); }
}
}
和
public class SummaryViewModel : ViewModelBase
{
public ObservableCollection<MyDate> MyCollection { get; set; }
}
和
public class MyDate
{
public DateTime CalcDate { get; set; }
}