简体   繁体   中英

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

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

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

您可以使用工具包中的wrappanel http://go.microsoft.com/fwlink/p/?LinkId=267555

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM