Dynamic tab control in WPF using MVVM pattern is pretty much simple.
For example
XAML
<TabControl Name="tabDynamic" ItemsSource="{Binding CurrencyList}" SelectionChanged="SelectedCurrency">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text={Binding CurrenyName}>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
ViewModelCode
ObservableCollection<CurrencyDTO> _currencyList;
public ObservableCollection<CurrencyDTO> CurrencyList
get
{
return _currencyList;
}
set
{
_currencyList=value;
OnPropertyChange(CurrencyList);
}
CurrencyDTO _selectedCurrency;
public CurrencyDTO SelectedCurrency
get
{
return _selectedCurrency;
}
set
{
_selectedCurrency=value;
OnPropertyChange(SelectedCurrency);
}
You can fill CurrencyList Collection by making server call. If you get 3 currency in this you will get 3 tab in your xaml at runtime.
On selection on any tab you control goes to SelectedCurrency this property now you can apply your logics inside this property.
CurrenyName is property which you made in your CurrencyDTO. We bind this property to show text in Tab. I want to show CurencyName that why i bind currencyname. You can bind any property which is in your CurrencyDTO.
Thanks
Please feel free to ask any question folks.