Tee
Tee

Reputation: 39

Is there an alternative to Wrap Panel in windows phone (8/8.1) apps

I have a ListBox whose ItemsSource is bound to a collection of Objects. My button content is bound to MyObject property "Name". When displaying on the UI, i want to wrap my buttons in such away that when they reach the end of the app i start displaying them in another new line of buttons . Apparently i am only displaying the first few buttons and the rest is cut off. The Wrap Panel which i was counting on seems to have been phased out.

My view (xaml):

<ListBox Grid.Row="1" ItemsSource="{Binding Objects}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"></StackPanel>
          </ItemsPanelTemplate>
        </ListBox.ItemsPanel>


        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <Button  Margin="2" Content="{Binding Name}" Width="200" />                     
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

My ViewModel:

public ObservableCollection<MyObject> Objects { get; set; }
    public MainViewModel()
    {
        Objects = new ObservableCollection<MyObject>();
        Add();
    }

    private void Add()
    {
      for (int i = 0; i < 15; i++)
        {
          Objects.Add(new MyObject() { Name = i});
        }
     }


    public class MyObject
    {
        public int Name { get; set; }


    }

ANY IDEAS !! THANKS

Upvotes: 3

Views: 2031

Answers (2)

Ronan Thibaudau
Ronan Thibaudau

Reputation: 3603

You could use the wrappanel from the toolkit http://go.microsoft.com/fwlink/p/?LinkId=267555

Upvotes: 2

Willem van Rumpt
Willem van Rumpt

Reputation: 6570

You can use an ItemsWrapGrid for that scenario, used in a similar way:

<ListView ...>
    <ListView.ItemsPanel>
          <ItemsPanelTemplate>
               <ItemsWrapGrid .../>
          </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

Upvotes: 6

Related Questions