在Listbox中横向显示CheckBox

前台代码

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

后台动态添加CheckBox

 foreach(var i in listOfMonth)
{
CheckBox cbMonth = new CheckBox();
cbMonth.Content = new TextBlock() { Text = i + "月?" };
cbMonth.IsChecked = true;
cbMonth.Checked += new RoutedEventHandler(cbMonth_Checked);
cbMonth.Unchecked += new RoutedEventHandler(cbMonth_Checked);
this.sp.Children.Add(cbMonth);
}

循环读取

 foreach (var item in sp.Children)
{
if ((item as CheckBox).IsChecked ?? false)
{
int Month = Convert.ToInt32(((item as CheckBox).Content as TextBlock).Text.ToCharArray()[].ToString());
}
}

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

 <ListBox ItemsSource="{Binding DishesList}" Margin="0,58,0,21"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate >
<DataTemplate>
<!--修改圆角外边-->
<Border BorderThickness="" BorderBrush="#FFD9D6D6" Margin="0,5,0,0" CornerRadius="" >
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Width=""
Background="#FFD9D6D6">
<StackPanel Height="" Margin="10,0,0,0" HorizontalAlignment="Center" Background="#FFF5F3F3">
<Image
Source="{Binding dishesimage, Converter={StaticResource ImageConver}, Mode=TwoWay}"
Style="{StaticResource imagestyle}" />
<Canvas Height="" Margin="0,40,0,0" Background="Black"/>
</StackPanel>
<StackPanel Width="" Margin="20,0,0,0">
<TextBlock Text="{Binding dishesname}" Style="{StaticResource titlestyle}"/>
<TextBlock Text="{Binding dishesprice,Converter={StaticResource DispicConver},Mode=TwoWay}" Style="{StaticResource authorstyle}"/>
<TextBlock Text="{Binding typename}" Style="{StaticResource timestyle}"/>
<!--<Canvas Height="" Margin="0,40,0,0" Background="Black"/>-->
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

listbox横向排列的更多相关文章

  1. WPF ListBox 横向排列

    WPF ListBox 横向排列   如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如: <ListBox><L ...

  2. wpf之ListBox中ListBoxItem横向排列

    ListBox中ListBoxItem默认是纵向排列,可以通过自定义样式,让其横向排列, 如下Demo: XAML: <Window x:Class="ListBoxItemStyle ...

  3. Template、ItemsPanel、ItemContainerStyle、ItemTemplate(包括ListBox的Item子项是横向排列)

    Template.ItemsPanel.ItemContainerStyle.ItemTemplate 分类: WPF2011-10-12 10:13 4716人阅读 评论(0) 收藏 举报 data ...

  4. css ul li 横向排列

    因为li是块级元素,默认占一行的,要想实现横向排列,一般通过以下两个方法:float:left这样设置有一个问题,li浮动以后则脱离了文本流,即不占位置,如果它的父级元素有具体的样式且没有固定宽高,建 ...

  5. ul li横向排列及圆点处理

    如何用CSS制作横向菜单 让ul li横向排列及圆点处理   第一步:建立一个无序列表 我们先建立一个无序列表,来建立菜单的结构.代码是:<ul> <li><a href ...

  6. 原创: EasyUI Tree 最后一级 节点 横向排列

    原创: EasyUI  Tree 最后一级 节点 横向排列 转载请指明出处 必须要写在: onLoadSuccess 事件中 ddAuthTree.tree({ lines: true, checkb ...

  7. 如何定义让两个div横向排列

    方法一: 一般情况,默认的div是写一个换一行,那么如何定义两个div横向排列而不换行呢? div默认的display属性是block.所以每一个div都是新的一行,现在把display换成inlin ...

  8. 如何让div横向排列

    方法一: 一般情况,默认的div是写一个换一行,那么如何定义两个div横向排列而不换行呢? div默认的display属性是block.所以每一个div都是新的一行,现在把display换成inlin ...

  9. 无序列表li横向排列的间隙问题

    今天在写页面的时候,无意中遇到这样一个问题,就是无序列表li横向排列即做成导航栏时,列表项间有间隙. 如: 将列表项li变成列表块后(即将li标签设置为,display:inline-block后), ...

随机推荐

  1. HTML网页制作:[12]使用框架结构之frameset

    首先,我希望在你的目录下,有4个网页,各自显示不同的内容. 如图所示: 1.html显示“火影忍者” 2.html显示“英雄联盟” 3.html显示“嵌入式开发.网页开发.安卓开发” 4.html显示 ...

  2. c#简单缓存使用,添加和修改

    private void SetCache(string CacheKey, object objObject, DateTime dt) { System.Web.Caching.Cache obj ...

  3. String.Empty、string=”” 和null的区别

    String.Empty是string类的一个静态常量: String.Empty和string=””区别不大,因为String.Empty的内部实现是: 1 2 3 4 5 6 7 8 9 10 1 ...

  4. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

  5. ASP .Net Core 使用 Dapper 轻型ORM框架

    一:优势 1,Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,编译后就40K的一个很小的Dll. 2,Dapper很快.Dapper的速度接近与IDataReader,取列表 ...

  6. js中继承的方法总结(apply,call,prototype)

    一,js中对象继承 js中有三种继承方式 1.js原型(prototype)实现继承 代码如下: <SPAN style="<SPAN style="FONT-SIZE ...

  7. html5的video标签支持的视频格式

  8. div中嵌套div速度将会同样很慢

    ---恢复内容开始--- div中嵌套了div速度将会同样很慢   最近很多老板在我们公司做企业站的时候都会要求说:我要div+css的,不要表格建的那种,那样不利于优化.但我们发现就算给他们用div ...

  9. Linux--本地yum库

    Linux配置本地yum云: 第一步:把cd 挂载到目录树 mount /dev/cdrom /mnt/media 第二步:增加/etc/yum.repo.d/local.repo touch /et ...

  10. ApiDemos示例学习(1)——ApiDemos示例的导入

    ---恢复内容开始--- 今天准备开始写这个ApiDemos示例的学习日记了,放在网上以监督自己! 首先是导入该示例.如果我们在配置Android开发环境是,利用Android SDK 安装包中的SD ...