English 中文(简体)
缩略语
原标题:Bind DataGridTextColumn with calculation in MVVM

我在银星米克斯·米洛佩斯上是新的,我正在建立一个项目,在该项目中,我把数据输入数据。

我的数据库结构如下:

  • tblAuthorizationVarification (AuthorizationVarificationid, AuthorizationRequestid, number)

  • tblAuthorizationRequest (AuthorizationRequestid, name)

  • t VarificationDetails (DetailId, 批准Requestid, 数额)

我想在所有授权中显示总金额。

下面是我的代码,载于Model。 页: 1 Varification:

PagedCollectionView _AuthorizationVarificationList;

public PagedCollectionView AuthorizationVarificationList
{
  get { return _AuthorizationVarificationList; }
  set 
  {
     _AuthorizationVarificationList = value;
     OnPropertyChanged("AuthorizationVarificationList"); }
  }

  private void GetVarifications()
  {
    IsBusy = true;
    LoadOperation<AuthorizationVerification> loadOp = 
                          objContext.Load(objContext.GetCreditNotesQuery());

    loadOp.Completed += (sender, e) =>
    {
       IEnumerable<AuthorizationVerification> op = 
               ((LoadOperation<AuthorizationVerification>)sender).Entities;
       PagedCollectionView view = new PagedCollectionView(op);
       this.AuthorizationVarificationList = view;
       cnt = cnt - 1;
       if (cnt <= 0)
         IsBusy = false;
    };
  }

授权 隔离 清单在Gridview中具有约束力,如同样。

<sdk:DataGrid x:Name="grdCreditNotes" 
    ItemsSource="{Binding Path=AuthorizationVarificationList}" 
    SelectedItem="{Binding Path=SelectedCreditNote, Mode=TwoWay}" 
    AutoGenerateColumns="False" IsReadOnly="True" Grid.Row="2" 
    VerticalAlignment="Stretch" Margin="0,0,0,0">

    <sdk:DataGrid.Columns>
      <sdk:DataGridTextColumn Header="Credit No" 
         Binding="{Binding Path=AuthorizationVerificationId}" Width="200"/>

      <sdk:DataGridTextColumn Header="Amount" 
         Binding="{Binding Path=AuthorizationRequest.Amount}" MinWidth="100" 
         Width="*"/>

    </sdk:DataGrid.Columns>    
</sdk:DataGrid>

在电网领域,我能做些什么来显示特别授权的数量?

最佳回答

正如我前面已经建议的那样,你可以为收集项目设定一个观点模式,并按需要加以分类。

public class VerificationViewModel
{
    public int AuthorizationVerificationId { get; set; }

    public double Amount { get; set; }
}

之后,使用“LINQ”结构,将收集和回收物品分类:

loadOp.Completed += (sender, e) =>
{
   IEnumerable<AuthorizationVerification> op = 
           ((LoadOperation<AuthorizationVerification>)sender).Entities;

   var models = op.GroupBy(item => item.AuthorizationVerificationId)
                  .Select(g => new VerificationViewModel
                                { 
                                    AuthorizationVerificationId = g.Key, 
                                    Amount = g.Sum(gi => gi.Amount) 
                                })
                  .ToList();

   PagedCollectionView view = new PagedCollectionView(models);
   // Everything else is the same
}

//Also change the type of the property which is bound to SelectedItem
public VerificationViewModel SelectedCreditNote { get; set; }

并改变第二栏的约束性道路:

<sdk:DataGrid.Columns>
  <sdk:DataGridTextColumn Header="Credit No" 
     Binding="{Binding Path=AuthorizationVerificationId}" Width="200"/>

  <sdk:DataGridTextColumn Header="Amount" 
     Binding="{Binding Path=Amount}" MinWidth="100" Width="*"/>

</sdk:DataGrid.Columns>   

该法典应计算每伊德的数额。 如果你想要其他聚合物,你可以改变林克的盘问。

问题回答




相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签