locked
binding a slider with two list scrolls RRS feed

  • Question

  • hi.

    in my WPF project, i have two list boxes, that contains 1) image data and 2) information about the image.

    i would like to have a slider, which, when i slide, will slide both listboxes together so the image will always have the correct data.

    how do i enable that? or is there a better way?

    thx
    Monday, March 24, 2008 7:49 AM

All replies

  • Why don't you just use a single listbox and a DataTemplate that hosts image and additional informations?
    Corrado Cavalli [MVP]
    Monday, March 24, 2008 8:16 AM
  • hmm.

    any idea how i could implement that?
    Monday, March 24, 2008 1:02 PM
  • Using Corrado's suggestion, your ListBox element in XAML would look something like this:

    <ListBox x:Name="lstTest">
    <ListBox.ItemTemplate>
    <DataTemplate>
    <StackPanel Orientation="Horizontal">
    <Image Source="{Binding Path=imgpath" Width="25" Height="25" />
    <TextBlock Text="{Binding Path=imgdesc}" />
    </StackPanel>
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>

    The important part of this is the ItemTemplate of the ListBox. You are effectively overriding the default "layout" of the items in the Listbox. You can make it look anyway you would like. By overriding this at the ItemTemplate level, you don't affect the default behaviour of the ListBox. So you still get a selected item and it is still highlighted as it normally would be.
    MVP ASP/ASP.NET
    Wednesday, March 26, 2008 3:26 PM