【发布时间】:2015-02-28 20:32:33
【问题描述】:
我有这个视图模型类
public class SchoolViewModel : INotifyPropertyChanged
{
private ObservableCollection<Student> _Eleves= new ObservableCollection<Student>();
public ObservableCollection<Student> Eleves
{
get {
return _Eleves;
}
set {
_Eleves = value;
PropertyChanged(this, new PropertyChangedEventArgs("Eleves"));
}
}
public SchoolViewModel( )
{
}
public event PropertyChangedEventHandler PropertyChanged;
}
我添加了这个简单的页面:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:SchoolViewModel x:Key="Locator" />
</Window.Resources>
<Grid >
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding Eleves, Source={StaticResource Locator}}" ></DataGrid>
</Grid>
</Window>
我需要扩展数据网格的行为以使其更聪明我的意思是,我有这个模型类:
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public DateTime DateNaissance { get; set; }
}
我需要在类属性中添加一些属性,并让 datagrid 将其转换为 UI 控件:
例如:
[DatePicker]
public DateTime DateNaissance { get; set; }
会在绑定到DateNaissance的datagrid中生成一列Datepicker。
我该怎么做?最好和更简单的方法是什么?
谢谢
【问题讨论】:
标签: c# wpf mvvm datagrid annotations