2014-12-10 4 views
0

Я пытаюсь добавить значения в столбец Job, но он продолжает приближаться к 0. Почему это происходит?Добавление столбца списка просмотров в 0

enter image description here

MainWindow.xaml.cs:

int jobSum = 0; 
int bidSum = 0; 
foreach (dynamic item in PlotListView.Items) 
{ 
    jobSum += Convert.ToInt32(item.Jobs); 
    bidSum += Convert.ToInt32(item.Bids); 
} 
JobBidRatioTextBlock.Text = jobSum.ToString(); 

MainWindow.xaml:

<ListView x:Name="PlotListView" HorizontalAlignment="Left" Height="228" Margin="5,37,0,0" VerticalAlignment="Top" Width="424"> 
    <ListView.View> 
    <GridView AllowsColumnReorder="False"> 
    <GridViewColumn Width="99" Header="Plot" DisplayMemberBinding="{Binding PlotId}"/> 
    <GridViewColumn Width="99" Header="Area" DisplayMemberBinding="{Binding Area}"/> 
    <GridViewColumn Width="99" Header="Jobs" DisplayMemberBinding="{Binding Jobs}"/> 
    <GridViewColumn Width="99" Header="Bids" DisplayMemberBinding="{Binding Bids}"/> 
    </GridView> 
    </ListView.View> 
</ListView> 

Подробная информация о фоновом коде работает по адресу: http://pastebin.com/z5kpDcUM

+0

Что работает код в код-позади? И почему не связано это поле? – BradleyDotNET

+0

@BradleyDotNET - посмотрите http://pastebin.com/z5kpDcUM – methuselah

+0

Несвязанные: вместо того, чтобы пытаться реализовать собственное сопоставление реляционных/объектов, просто используйте Entity Framework. Тем не менее, почему вы используете динамический вместо правильного типа объекта? И если ваш столбец содержит числовые данные, почему вы привязываете его к свойству типа string вместо int? –

ответ

1

В вас конструкторе MainWindow чуть ниже InitializeComponent() написать это:

 InitializeComponent(); 
     DependencyPropertyDescriptor 
.FromProperty(ListView.ItemsSourceProperty, typeof(ListView)) 
.AddValueChanged(PlotListView, PlotListView_ItemsSourceChanged); 

Затем добавьте Funtion в MainWindow Класс:

 private void PlotListView_ItemsSourceChanged(object sender, EventArgs e) 
    { 
     ////Write your summation code here 
    }