Video Shelf but different ;-)


  • Hi,

    I want to make a some sort of scrollbar function in a stackpanel. This stackpanel has some buttons that when clicked open up(resizes, like a window that shows up). This works almost perfect but i have some questions. If i click a button that is at the far right of the stackpanel it gets all messy. So what i want to do is before it opens reposision it to a other place into the stackpanel. For example if you click the far right button of the stackpanel it first goes to the far left and opens up. But i have no idea how to do this. For example i want it to look like

    Hope someone can tell me what the right approach would be.

    Thursday, May 29, 2008 7:28 AM

All replies

  • Hello, I think you can handle the SelectionChanged event. Before expanding the ListBoxItem, you need to remove the selected item, and insert it back to the start of the item collection. Note currently there're some problems on ListBox. After remove an item, you need to manually set SelectedIndex to -1, or you'll encounter problems. Also you can't add the same ListBoxItem back to a ListBox, you have to create a new one.

     if (listBox1.SelectedIndex != 0 && listBox1.SelectedIndex != -1)
    ListBoxItem selected = (ListBoxItem)listBox1.SelectedItem;
    listBox1.SelectedIndex = -1;
    ListBoxItem newItem = new ListBoxItem();
    newItem.Content = selected.Content;
    //If you have set other properties such as Width on the original ListBoxItem, copy them to the new one.
    listBox1.Items.Insert(0, newItem);
    listBox1.SelectedIndex = 0;

    If you're using data binding, you should remove and add items on the data source rather than ListBox.Items.

    Sunday, June 01, 2008 11:21 PM
  • Ty for your reply.

    I actually found another way to accomplish what i want. What I did is that i put the stackpanel in a scrollviewer so that the stackpanel is scrollable. Now i made a mouse scroll wich means that if you move the mouse to the left the scrollviewer scrolls to the left and visa versa. I did this with GetPosition so that i can calculate where the mouse is and where to the scrollviewer have to scroll.

    Now i got another thing wich may be a bug or may just be the behaviour of something. so this image shows what happens when you click one of the menu items( it opens up with a storyboard): visible  As you can see that this is normal but when i scroll to the far left i get the following: invisible . Is this a common bug or is this normal behaviour if so is there something i can do about it?

    Extra info: It only happends to the fifth from the left and it doesnt happen at the left side of the screen. I also tried to change the buttons but it still happens so i think this is a bug.

    Monday, June 02, 2008 4:26 AM