views:

44

answers:

2

How would I create a control like the example at this site as a User Control?

So, instead of doing this:

<ScrollViewer>
    <StackPanel>
        <!– Content –>
    </StackPanel>
</ScrollViewer>

I could do this:

<ScrollableStackPanel>
    <!– Content –>
</ScrollableStackPanel>
+1  A: 

Unfortunately, there is no way to do that as a UserControl in WPF. You would need to make a custom control (instead of a user control) based on ItemsControl. It could handle this correctly.

That being said, I don't see much point in this. It's very easy to just put your StackPanel within a ScrollViewer - why reinvent the wheel?

Reed Copsey
I'm trying to make a type of StackPanel that is scrollable and it's items are Drag n Droppable
c00lryguy
Why not just use a ListBox or a StackPanel in a ScrollViewer? Otherwise, you need to make a custom control - you can't have a user control be an ItemsControl (which lets you have multiple "content" elements)...
Reed Copsey
Reed is right. This is the entire point of WPF's separation of visual and behavioral aspects of controls. You wouldn't know by looking at them but a TabControl and ListBox are nearly the same exact control, both deriving from Selector. You should instead look into replacing ListBox's style and/or ItemTemplate.
Josh Einstein
A: 

It looks like you just need to use a ListBox. You can override the ItemContainterStyle and ListBox.Style to get rid of all the Selected behaviours and backgrounds if you want. Because a ListBox has StackPanel and ScrollViewer in it by default.

Jobi Joy