views:

34

answers:

2

How can I go about creating a control that has items in item that list vertically, but only to the height of the control, then start at the top of the second column?

Sort of like the windows explorer look and feel.

I am using a WrapPanel at the moment, but I cannot figure out how to make it scroll horizontally...

Any help here is greatly appreciated

Cheers, Mark

A: 

Sounds alot like a UniformGrid or a WrapPanel to me check this blog, he has some nice demos of the built-in layout panels

Muad'Dib
The only problem with that is that the WrapPanel doesnt scroll, and I need it to, and Im assuming the same for the UniformGrid...
Mark
+2  A: 

Enclose a WrapPanel with vertical orientation within a ScrollViewer with VerticalScrollbarVisibility set to Disabled.

Paste this into Kaxaml and you'll see:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  <Page.Resources>
    <Style TargetType="{x:Type Button}">
      <Style.Setters>
        <Setter Property="Width" Value="50"/>
        <Setter Property="Height" Value="50"/>
      </Style.Setters>
    </Style>
  </Page.Resources>
  <Grid Margin="200, 100">
    <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Visible" MaxWidth="200">
    <WrapPanel Orientation="Vertical">
      <Button/>
      <Button/>
      <Button/>
      <Button/>
      <Button/>
      <Button/>
      <Button/>
      <Button/>
      <Button/>
    </WrapPanel>
    </ScrollViewer>
  </Grid>
</Page>
Robert Rossney
If you set the VerticalScrollBarVisibility to Disabled, you don't need to set MaxHeight.
Abe Heidebrecht
Fixed. For some reason I forgot that `Visibility.Disabled` even existed.
Robert Rossney
works very well, although I had some initial trouble, I was using a Canvas instead of a grid, and the scrollbar did not show up when there was a lot of content in the wrappanel, why is that?
Mark
If you're using a `Canvas`, you have to provide an explicit size and position for child content. `Canvas` is really super-primitive; you shouldn't use it for laying out UI controls in most circumstances because it doesn't do any kind of default layout; you have to tell it everything about where to put the child elements and how big they are yourself.
Robert Rossney