Solved

How to dynamically add checkboxes to a Stack Panel

Posted on 2012-04-02
1
929 Views
Last Modified: 2012-04-05
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;    



        }
0
Comment
Question by:countrymeister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 37799934
to dynamically add controls to stack panel you should add to the Children collection:
http://msdn.microsoft.com/en-us/library/ms743314.aspx#Y0
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question