In my application I store an array of structs containing how much bills/coins i need to pay to a client and how many I effectively pay.
public struct MoneyType
{ //contains more, but left out for readability
public int Requested { get; set; } // How many are requested for a payment
public int Paid { get; set; } //bills paid to the customer
}
I made an array with these which I make accessible to the viewmodel in the following way:
MoneyType[] money; //correctly initialised in the constructor
public MoneyType[] GetMoney()
{
return money;
}
In the viewmodel itself I make these accessible in this way:
public MoneyType[] MoneyTypes //Denominations
{
get
{
return _dataService.GetMoney();
}
}
Finally, in my XAML, I accessed these as:
<cbtn:BillCounter x:Name="euro200" Value = "{Binding MoneyTypes[2].Paid, Mode=TwoWay }" />
The [2] is used to indicate which type of bills/coins I want to use.
I want to make this work 2 ways, so that my custom control can update the amount of coins/bills paid. For which I would need a setter for my MoneyTypes property.
I'm not sure the right way to do this. I have a feeling that somehow, I should not pass the entire array from my viewmodel/model, but a specific part of one of my MoneyTypes (the paid/requested fields, with some kind of index indicating which entry to use)
I'm unsure of how to do this.