Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

How to dynamically add checkboxes to a Stack Panel

I have a stack panel and would like to dynamically add check boxes based on a list of items I get from a list.

 <StackPanel Grid.Row="5" Height="26"  Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="30,28,0,0" Name="stackPanelPlatform" VerticalAlignment="Stretch" Width="1041"   Loaded="stackPanelPlatform_Loaded">
            <ItemsControl Name="SPPlatforms" ItemsSource="{Binding platforms}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <CheckBox  Content="{Binding Text}" IsChecked="{Binding IsChecked}" Width="200" Name="{Binding Text}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </StackPanel>



Code Behind
private void stackPanelPlatform_Loaded(object sender, RoutedEventArgs e)
        {

            var platforms = new ObservableCollection<Platform>();
            Platform pt = new Platform { Text = "ABC", IsChecked = false };
            platforms.Add(pt);
            pt = new Platform { Text = "XYZ", IsChecked = false };
            platforms.Add(pt);

            SPPlatforms.ItemsSource = platforms;    



        }
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial