为了演示效果,模拟了一个餐饮系统点餐的界面,不多说,直接上代码

前台

  <ListBox x:Name="dglist" Grid.Row="1" Grid.Column="0"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel HorizontalAlignment="Left"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Button Width="100" Height="80" Content="{Binding Name}" Background="{Binding State,Converter={StaticResource DeskStateConvert}}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
   </ListBox>

后台没什么代码,主要是给ListBox赋值

DeskCollection desks = new DeskCollection();
            for (int i = 0; i < 21; i++)
            {
                int state = 0;
                if (i > 6)
                    state = 1;
                if (i > 10)
                    state = 2;
                if (i > 15)
                    state = 3;

                Desk d = new Desk() { Name = "A" + i.ToString("00"), State = state };
                desks.Add(d);
            }
            dglist.ItemsSource = desks;

效果预览

Silverlight LIstBox 实现横向排列元素 并且自动换行

 

相关文章:

  • 2021-12-02
  • 2021-08-21
  • 2022-02-14
  • 2021-12-25
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案