0

In my project, I need to show a list of buttons with choices in custommessagebox.

Now, I have no problem in setting it up, but when I create the longlistselector, add it to scrollviewer and show the cusstommessagebox, only a few buttons are shown and i can't scroll for more.

The code I have is following:

    private void btnChronicity_ButtonClicked(object sender, Events.LinkEventArgs e)
    {
        editBox = new CustomMessageBox() 
        {
           ....
        };

        ScrollViewer viewer = new ScrollViewer();
        choiceSelector = new Controls.MessageBocChoiceSelectorControl();
        List<items> chronicity = new List<items>();
        foreach (ChronicityModel chronicity in ...Chronicities)
        {
            chronicity.Add(new items(chronicity.Name, chronicity.Selected, chronicity.Id));
        }

        choiceSelector.ItemSource = chronicity;
        editBox.Content = viewer;
        editBox.Show();
    }

and the choiceselector is usercontrol, which looks like:

<StackPanel>
    <Controls:LongListSelector x:Name="LayoutRoot">
        <Controls:LongListSelector.ItemTemplate>
            <DataTemplate>
                <Controls1:CheckableListButton Header1="{Binding Header}"
                                           Selected="{Binding Selected}"
                                           Link="{Binding Link}"
                                           ButtonClicked="CheckableListButton_ButtonClicked"/>
            </DataTemplate>
        </Controls:LongListSelector.ItemTemplate>
    </Controls:LongListSelector>
</StackPanel>

where listbutton is another control, basically button containing several textBlocks, boolean indicating whether it is selected (another style) or not and a string Link, which is returned in custom click event.

The result looks this way: Problem

But the problem is I can't scroll...

Why is it behaving like that? How to fix it?

EDIT:

As I play with the longlistselector and stuff around I have found out that the scrolling works, the problem is the LongListSelector only loads as much items as fits the messagebox instead all of them..... (when i create smaller messagebox, it shows less items, when i create bigger, it shows more)

So the question shifted a bit to:

HOW TO MAKE LONGLISTSELECTOR SHOW ALL OF THE ITEMS INSTEAD OF JUST AS MUCH AS FITS THE SCREEN.

mishan
  • 1,177
  • 3
  • 19
  • 42
  • You doesn't seem to be fixing the height of scrollviewer. Try to give some Height to ScrollViewer, so that scrolls when its childs height is more than its height – nkchandra Dec 10 '13 at 05:18
  • you can not make longlistselector in scrollviewer – techloverr Dec 10 '13 at 05:19
  • where is solution on that page? – techloverr Dec 10 '13 at 06:42
  • I don't mean that there is a solution on that page, I just mean that he is using longlistselector in scrollviewer and it works, so I don't see why u're telling it's not possible when it clearly is. – mishan Dec 11 '13 at 09:54

3 Answers3

3

So there are three distinct problems I see with the code:

  1. You are creating a new instance of the ScrollViewer in C#, but you are not actually adding the choiceSelector instance to the viewer instance. Not sure if you just left that out in your sample, or you are not actually adding it.

  2. I would not recommend adding a LongListSelector in a ScrollViewer.... because it already scrolls by default. Your problem is that you're putting the LongListSelector in a StackPanel, which will not constrain the height of the LongListSelector in any way.

    Instead I would put the LongListSelector in a Grid control, with the row height defined as *. This will mean that the Grid height is constrained to the parent container.

  3. Having said that, have you looked into the ListPicker control from the http://phone.codeplex.com Toolkit? That seems like it is a little closer to what you are looking for.

HTH

Community
  • 1
  • 1
Robert McLaws
  • 2,258
  • 2
  • 19
  • 22
  • 1. Yep, it's just left out of the sample. I'll fix it. 2. I don't know, it usually does not then I'm using it. Is there some property I should set so it would? 3. Didn't knwo about listpicker, I'll look into it in my spare time :) – mishan Dec 10 '13 at 05:58
  • 2. - Read about it, but never encountered it. Even though I changed the stackpanel for grid (with rowdefinition set to * and longlistselector specifically se to that row), it does not work. – mishan Dec 10 '13 at 06:12
  • Perfect. I had a LongListSelector in a StackPanel and it lost its ability to scroll for the reasons given above. Changed to a Grid and it's good now. – Jon Jun 07 '14 at 16:15
0

This is how I used longlistselector in my code and it works perfectly for me with infinite scrolling. See if it helps you.

<Grid Background="#FFE6E2E2" Margin="10,10,0,0">
 <phone:LongListSelector x:Name="lb" Margin="0,0,0,0" ItemTemplate="{StaticResource ItemTemplate}"></phone:LongListSelector>
</Grid>
Hitesh
  • 3,449
  • 8
  • 39
  • 57
  • Can you please try it inside CustomMessageBox (part of Windows Phone Toolkit)? Because the solution I have works on regular page, but not inside CustomMessageBox - plus the textWrapping on it stopped working too even though I have maximum width set.... – mishan Dec 11 '13 at 09:57
0

Restrict the height of the longlistselector to some 200 or so, which is less than the height of the usercontrol. Make sure you mention the Height = " " property in the xaml of the longlist selector.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222