TB007
Member
- Joined
- Aug 13, 2022
- Messages
- 24
- Programming Experience
- Beginner
I have a Employees model with properties
In my XAML I have datagrid set up with an ICollectionView
In my viewmodel in a method I want to get the sum of
I was thinking something like below but it doesn't work.
C#:
private int _id;
public int Id
{
get
{
return _id;
}
set
{
SetValue(ref _id, value);
}
}
private string _empname;
public string EmpName
{
get
{
return _empname;
}
set
{
SetValue(ref _empname, value);
}
}
private string _empsalary;
public string EmpSalary
{
get
{
return _empsalary;
}
set
{
SetValue(ref _empsalary, value);
}
}
//...other properties like age, address etc.
//this property is for datagrid selected rows
private bool _isSelected;
public bool IsSelected
{
get { return _isSelected; }
set
{
SetValue(ref_isSelected, value);
}
}
In my XAML I have datagrid set up with an ICollectionView
FilteredEmps
as its itemsource and also
C#:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="IsSelected" Value="{Binding Path = IsSelected}"/>
</Style>
</DataGrid.RowStyle>
EmpSalary
of the selected items of the datagrid. How can I do that following MVVM pattern?I was thinking something like below but it doesn't work.
C#:
public static decimal SumSalary()
{
return FilteredEmps.Cast<Employees>().Select(i=>i.IsSelected).Sum(j => Convert.ToDecimal(j.EmpSalary.ToString()));
}