I am basically using this code and I am successfully adding CheckBox
es (instead of ComboBox
that is in the example) to my View
. The problem however is that I want to be able to customize (different Content
, binding, etc) those CheckBox
es. Right now when I add a CheckBox
it adds the default one that is defined in my DataTemplate
.
DataTemplate
:
<DataTemplate DataType="{x:Type local:CurrencyViewModel}">
<StackPanel Orientation="Vertical">
<CheckBox Content="Default"/>
</StackPanel>
</DataTemplate>
CurrencyViewModel
- the code here is NOT used by the program and I am not sure why, but I am pretty sure that this is the problem
class CurrencyViewModel : INotifyPropertyChanged
{
public CurrencyViewModel(ICurrency currency)
{
CheckBox currencyCheckBox = new CheckBox()
{
Content = currency.Name,
};
OnPropertyChanged("CurrenciesList");
}
MainViewModel
:
public MainViewModel()
{
foreach (ICurrency currencyin GetAllCurrencies())
{
CurrenciesList.Add(new CurrencyViewModel(currency));
}
}
private ObservableCollection<CurrencyViewModel> _CurrenciesList = new ObservableCollection<CurrencyViewModel>();
public ObservableCollection<CurrencyViewModel> CurrenciesList
{
get
{ return _CurrenciesList; }
set
{
_CurrenciesList = value;
OnPropertyChanged("CurrenciesList");
}
}