2
votes

I have used a list box to display few dates. A string contains a date followed by a number. And this date is written to as an item to the listbox. I have put white spaces after the date. But it has alignment problem. Is there anyway I can set tab after the date? Or is there a way to set columns for listbox?

Mon, Sep 1, 2011 26

Thu, Oct 16, 2011(longer..) 30

I cant use a grid because, the items will be dynamically generated, so the number of rows cannot be known before hand.

Is there any control with scroll bars which can display values in the above manner? There no control called the ListView in WP7 right?. No binding is used here, so i cant use the DataTemplate!! Help!!

Alfah

5
asking the obvious first question - why is there no binding? and you don't need a control with scrollbars, since you can wrap most things in a scrollviewer - Henry C
Bindings are a good thing. Not using bindings is not only silly, it's also stupid. - Claus Jørgensen

5 Answers

2
votes

Check the answer for this question, might be helpful because what you're asking about can be done this way.

UPDATE: In that case you'll have to do it using c# code as follows:
1- Add the date to a textblock:

TextBlock t = new TextBlock();
t.Text = _Date_;
t.Width = 100;  // set width you want to make all date entires have the same width

2- Add the number to another textblock:

TextBlock n = new TextBlock();
n.Text = _number_;
n.Width = 50;  // set width you want to make all date entires have the same width

3- Add them both to a stackpanel:

StackPanel st = new StackPanel();
st.Orientation = System.Windows.Controls.Orientation.Horizontal;
st.Children.Add(t);
st.Children.Add(n);

4- Add the stack to the listbox:

listBox1.Children.Add(st);

And you'll have to repeat this for every element you want to add.

2
votes

You can use WrapPanel as ItemsPanel from Silverlight Toolkit, Please check the following: http://www.geekchamp.com/articles/wp7-wrappanel-in-depth and http://www.codeproject.com/Questions/507167/Windowsplusphoneplus7plusHowplustoplusshowplustwop


1) Download Silverlight for Windows Phone Toolkit
2) Add Referance: Microsoft.Phone.Controls.Toolkit
3) Add the following in phone:PhoneApplicationPage source code
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
4) Listbox control example:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <toolkit:WrapPanel ItemWidth="100" ItemHeight="50"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBoxItem Content="Item1"/>
    <ListBoxItem Content="Item2"/>
    <ListBoxItem Content="Item3"/>
    <ListBoxItem Content="Item4"/>
    <ListBoxItem Content="Item5"/>
    <ListBoxItem Content="Item6"/>
</ListBox>
0
votes

I am not sure if I understand your problem. But I am guessing, using a stackpanel with horizontal orientation should help. Any luck with Expression Blend? You might find controls that can solve your problem.

0
votes

you can set the template for ListItem. If it will be a grid with two columns it solves your problem

0
votes

Use a Grid. And databind it. Seriously, no reason to fool around with any other solutions.