Hi,
I have a list of workers, whom all needs to have an amount paid by way of their hours times a value.
I have a WorkerModel class:
public class WorkerModel{ public string Name { get; set; } public int HoursWorking { get; set; }}Then I have a CompanyModel that contains the workers:
public class CompanyModel{ private ObservableCollection<WorkerModel> _workers = new ObservableCollection<WorkerModel>(); public ObservableCollection<WorkerModel> Workers { get { return _workers ; } set { _workers = value; } }}And then I have a ViewModel that allows me to bind to the view:
public class MainViewModel : ViewModelBase{ private readonly CompanyModel _company; public MainViewModel() { _company= new CompanyModel(); } public ObservableCollection<CompanyModel > Workers { get { return _company.Workers; } } public decimal PayoutPerHour { get { return 71M; } }}Lastly my view looks like this:
<telerik:RadGridView ShowGroupPanel="False" HorizontalAlignment="Left" telerik:StyleManager.Theme="Summer" AutoGenerateColumns="False" GroupRenderMode="Flat" NewRowPosition="Bottom" ItemsSource="{Binding Workers}" Grid.Column="0"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Path=Name}" Width="230"></telerik:GridViewDataColumn> <telerik:GridViewExpressionColumn Header="Payout" Width="100" Expression="HoursWorking * PayoutPerHour"></telerik:GridViewExpressionColumn></telerik:GridViewDataColumn> </telerik:RadGridView.Columns> </telerik:RadGridView>
My goal is to have the HoursWorking from the WorkerModel, multiply with the PayoutPerHour thats in the ViewModel. I have in this example made the PayoutPerHour a static value, which it is not in my full example. I need the Expressioncolumn to update whenever either of those two properties are updated. But I can't tell the viewmodel what the WorkerModel is doing, since they are in a collection in the CompanyModel.
Any clever way to do this?
