开发者

ViewModel do not display element in datagrid

开发者 https://www.devze.com 2023-01-27 21:43 出处:网络
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\".

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消