StackPanel Issue? RRS feed

  • General discussion

  • I had an idea for a configurable silverlight sight for myself and I wanted a simple navigation system that was driven by an XML file. I also wanted to use an MVVM design pattern. So, following Tim Heuer's example video here I essentially took his example and converted "Question" to "MenuItem" and virtually all the code is identical (with a few naming conversions). When I run my sample my stackpanel alwyas remains oriented to default "Vertical". What I wanted was a Horizontal menu, but no matter what I change in the XAML something is happening to the ItemsControl DataTemplate where it is always stacked Vertically. Any help would be appreciated...

    This is in the MainPage.xaml

    <Menu:MenuViewControl x:Name="Menu" Canvas.Left="50" Canvas.Top="50" Width="Auto"/>

    This is the menu control XAML... 

    <UserControl x:Class="ATLED.View.MenuViewControl"






    d:DesignHeight="300" d:DesignWidth="400">


    <Canvas x:Name="menuRoot" Background="Beige">

    <StackPanel Orientation="Horizontal" Background="#FF336699" Width="Auto" Height="Auto">

    <ItemsControl ItemsSource="{Binding}">



    <TextBlock Text="{Binding Path=text}" FontWeight="Bold" Margin="2"></TextBlock>







    Monday, June 14, 2010 2:27 PM

All replies

  • Try putting this


                        <StackPanel Orientation="Horizontal" ></StackPanel>

     after this:

    <ItemsControl ItemsSource="{Binding}">

    Monday, June 14, 2010 2:37 PM
  • Thanks... but that did not work...

    At this juncture I would simply like to see any XAML work... For some odd reason no matter what I do using the MVVM methodology it causes the stackpanel to put it out Vertically no matter what.

    Everything else works except the output in XAML... This has to be something really simple or really stupid that I'm missing... 

    Monday, June 14, 2010 3:23 PM
  • Look at your XAML. Your StackPanel is completely unrelated to your ItemsControl, apart from that fact that it happens to contain it. It contains one item: your ItemsControl. So quite how you would expect it to lay out its children horizontally or vertically is unclear. It only has one item. You seem to be expecting your ItemsControl to be using the StackPanel to host its child items in.

    You need to specify a StackPanel as the ItemsPanel for your ItemsControl, as the other poster said. This will cause the ItemsControl to use that StackPanel to host its children in.


    Monday, June 14, 2010 4:36 PM
  • Thank you for the info...

    I am a relative newbie to XAML templating paradime... I will take a closer look at the XAML. The programming piece was easy enough, but obviously I need some work in the UI playground.

     I figured it was my own error, but after 4 or 5 attempts I started looking for help. I appreciate your feedback.

     Thank you very much...  

    Monday, June 14, 2010 5:10 PM