Currently my model has ten properties which for our purposes here I'll call AnnualizedRate1
, AnnualizedRate2
, ..., AnnualizedRate10
which are revealed to views in the view model via ten properties Rate1
, Rate2
, ..., Rate10
. One of my views shows these values in a DataGrid
. This is awfully repetitious and a pain to adapt to changing requirements. There has to be a better way than the following.
Model (MyModel
):
public decimal AnnualizedRate1 { get { return this.AnnualizedRate(1); } }
public decimal AnnualizedRate2 { get { return this.AnnualizedRate(2); } }
...
public decimal AnnualizedRate10 { get { return this.AnnualizedRate(10); } }
where MyModel.AnnualizedRate
is
public decimal AnnualizedRate(int i);
View Model (MyViewModel
):
public decimal Rate1 { get { return myModel.AnnualizedRate1; } }
public decimal Rate2 { get { return myModel.AnnualizedRate2; } }
...
public decimal Rate10 { get { return myModel.AnnualizedRate10; } }
View (MyView
):
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
...
<dg:DataGrid>
<dg:DataGrid.Columns>
<dg:DataGridTextColumn
Header="Rate1"
Binding="{Binding Rate1, StringFormat=P}"
IsReadOnly="True"/>
<dg:DataGridTextColumn
Header="Rate2"
Binding="{Binding Rate2, StringFormat=P}"
IsReadOnly="True"/>
...
<dg:DataGridTextColumn
Header="Rate10"
Binding="{Binding Rate10, StringFormat=P}"
IsReadOnly="True"/>
</dg:DataGrid.Columns>
</dg:DataGrid>
Does anyone have any ideas?