Если вам нужно захватить их значения в модели представления, добавление флажков в выделенном фрагменте кода может быть не лучшим подходом.
class MainWindowViewModel : INotifyPropertyChanged
{
private int _sliderValue;
public int SliderValue
{
get
{
return _sliderValue;
}
set
{
_sliderValue = value;
while ( SliderValue > CheckboxValues.Count )
{
CheckboxValues.Add( false );
}
// remove bools from the CheckboxValues while SliderValue < CheckboxValues.Count
// ...
}
}
private ObservableCollection<Boolean> _checkboxValues = new ObservableCollection<Boolean>();
public ObservableCollection<Boolean> CheckboxValues
{
get
{
return _checkboxValues;
}
set
{
if ( _checkboxValues != value )
{
_checkboxValues = value;
RaisePropertyChanged( "CheckboxValues" );
}
}
}
, тогда в xaml, что-то вроде:
<ItemsControl ItemsSource="{Binding CheckboxValues}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type sys:Boolean}">
<CheckBox IsChecked="{Binding self}">Hello World</CheckBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>