I have one comboBox with value [ days,weeks,months,years]
<ComboBox Width="130" Margin="0,10,0,16" ItemsSource="{Binding PeriodCollection }"
SelectedItem="{Binding SelectedDuration }"
Text="" DisplayMemberPath="Name" />
Beside comboBox , I have one Textbox. If user selects "weeks" from comboBox and put value 2 in textbox, in database I have to save 2*7 = 14 [ days].
To do this functionality I have created period collection.
public class Period : BaseObject
{
private string name;
public string Name
{
get { return name; }
set { name = value; NotifyPropertyChanged(); }
}
private int numberOfDays;
/// <summary>
/// number of days in period
/// </summary>
public int NumberOfDays
{
get { return numberOfDays; }
set { numberOfDays = value; NotifyPropertyChanged(); }
}
public Period(string perdioName, int numberOfDayInPeriod)
{
Name = perdioName;
NumberOfDays = numberOfDayInPeriod;
}
}
}
public static class PeriodManager
{
private static ObservableImmutableList<Period> periodCollection;
/// <summary>
/// return a collection of time period in days ///
/// </summary>
/// <returns>Days, Week,Month, year</returns>
public static ObservableImmutableList<Period> GetPeriodCollection()
{
if (periodCollection == null)
{
periodCollection = new ObservableImmutable.ObservableImmutableList<Entities.Period>();
periodCollection.Add(new Period("Days", 1));
periodCollection.Add(new Period("Week", 7));
periodCollection.Add(new Period("Month", 30));
periodCollection.Add(new Period("Year", 365));
}
return periodCollection;
}
/// you can create method can return a period from a day number...
}
Now in my viewModel I am trying to implement a method which will return days.
private ObservableImmutableList<Period> periodCollection;
public ObservableImmutableList<Period> PeriodCollection { get { return periodCollection; } set { periodCollection = value; NotifyPropertyChanged(); } }
private Period selectedDuration;
public Period SelectedDuration { get { return selectedDuration; } set { selectedDuration = value; NotifyPropertyChanged(); } }
private void GetPeriod()
{
PeriodCollection = PeriodManager.GetPeriodCollection();
//here I need to write logic to merge from both values [ txtBox+combox]
}
But I am confused with -
while saving how I'll merge with textbox value with returned value of combobox days [ if entered 2 in textbox and selected week in comobox, i need value 14]
Please help me with this in wpf mvvm concept. I tried in web but was not able to find any in mvvm.