How can i stop a WPF DataGrid form automatic display an element binded to an datagrid.
I have this view model where i don't want it to display the element "History". I have tryed with [Display(AutoGenerateField = false)] but it dose not work.
The way i have it here will it display Lead, Calls, LastCall and then all the elements again.
<DataGrid ItemsSource="{Binding Leads}" Margin="0" FontSize="20">
<DataGrid.Columns>
<DataGridTextColumn Header="Lead" Binding="{Binding Lead}" Width="150" />
<DataGridTextColumn Header="Calls" Binding="{Binding Calls}" Width="150" />
<DataGridTextColumn Header="LastCa开发者_开发问答ll" Binding="{Binding LastCall}" Width="*" />
</DataGrid.Columns>
View Model
public class LeadViewModel : ViewModel
{
[Display(AutoGenerateField = false)]
public int Lead { get; set; }
[Display(AutoGenerateField = false)]
public int Calls
{
get
{
return History.Count();
}
}
[Display(AutoGenerateField = false)]
public int EndCalls
{
get
{
return (from h in History
where h.DailTime.End != null
select h).Count();
}
}
[Display(AutoGenerateField = false)]
public int Jobs
{
get
{
return (from h in History
where h.DailTime.End != null
select h.ProjectJob).Distinct().Count();
}
}
[Display(AutoGenerateField = false)]
public DateTime? LastCall
{
get
{
return (from h in History
orderby h.DailTime.Start descending
select h.DailTime.Start).FirstOrDefault();
}
}
[Display(AutoGenerateField = false)]
public IQueryable<DailHistory> History { get; set; }
}
Bij setting the AutoGenerateColumns property to false:
<DataGrid AutoGenerateColumns="False">
</DataGrid>
It defaults to true, and thus adding all the columns of the itemssource to the datagrid.
精彩评论