码迷,mamicode.com
首页 > 其他好文 > 详细

listbox横向排列

时间:2015-01-31 15:56:55      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

在Listbox中横向显示CheckBox

前台代码

1 <ListBox Height="30" HorizontalAlignment="Left" Margin="231,25,0,0" Name="listMonth" VerticalAlignment="Top" Width="747" >
2             <StackPanel x:Name="sp" Orientation="Horizontal">
3                 需要添加的元素
4             </StackPanel>
5 </ListBox>

后台动态添加CheckBox

技术分享
1 foreach(var i in listOfMonth)
2             {
3                 CheckBox cbMonth = new CheckBox();
4                 cbMonth.Content = new TextBlock() { Text = i + "月?" };
5                 cbMonth.IsChecked = true;
6                 cbMonth.Checked += new RoutedEventHandler(cbMonth_Checked);
7                 cbMonth.Unchecked += new RoutedEventHandler(cbMonth_Checked);
8                 this.sp.Children.Add(cbMonth);    
9             }
View Code

循环读取

技术分享
1 foreach (var item in sp.Children)
2                 {
3                     if ((item as CheckBox).IsChecked ?? false)
4                     {
5                         int Month = Convert.ToInt32(((item as CheckBox).Content as TextBlock).Text.ToCharArray()[0].ToString());
6                      }
7                 }
View Code


除了这种方法外还有一种方式:横排模版

技术分享
 1 <ListBox ItemsSource="{Binding DishesList}" Margin="0,58,0,21"
 2                      ScrollViewer.VerticalScrollBarVisibility="Disabled" 
 3 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
 4                 <ListBox.ItemsPanel>
 5                     <ItemsPanelTemplate>
 6                         <toolkit:WrapPanel Orientation="Horizontal"/>
 7                     </ItemsPanelTemplate>
 8                 </ListBox.ItemsPanel>
 9                 <ListBox.ItemTemplate >                  
10                     <DataTemplate>                        
11                         <!--修改圆角外边-->
12                     <Border BorderThickness="5"  BorderBrush="#FFD9D6D6" Margin="0,5,0,0" CornerRadius="5" >
13                         <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center"  Width="300"
14                                     Background="#FFD9D6D6">
15                             <StackPanel Height="80" Margin="10,0,0,0" HorizontalAlignment="Center"  Background="#FFF5F3F3">
16                                     <Image
17                                         Source="{Binding dishesimage, Converter={StaticResource ImageConver}, Mode=TwoWay}"
18                                         Style="{StaticResource imagestyle}" />
19                                 <Canvas  Height="1" Margin="0,40,0,0" Background="Black"/>
20                             </StackPanel>
21                             <StackPanel Width="250" Margin="20,0,0,0">
22                                     <TextBlock  Text="{Binding dishesname}" Style="{StaticResource titlestyle}"/>
23                                     <TextBlock  Text="{Binding dishesprice,Converter={StaticResource DispicConver},Mode=TwoWay}" Style="{StaticResource authorstyle}"/>
24                                     <TextBlock  Text="{Binding typename}" Style="{StaticResource timestyle}"/>
25                                 <!--<Canvas  Height="1" Margin="0,40,0,0" Background="Black"/>-->
26                             </StackPanel>
27                         </StackPanel>
28                     </Border>
29                 </DataTemplate>
30             </ListBox.ItemTemplate>
31             </ListBox>
View Code

 

listbox横向排列

标签:

原文地址:http://www.cnblogs.com/lsqandzy/p/4264071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!