关于 silverlight 下拉多选CheckedComboBox自定义控件

安静9527 2016-08-12 02:08:20
http://www.cnblogs.com/shiaupo/archive/2011/06/04/2072668.html
关于这个控件有谁用过...
绑定键值对
里面可以得到SelectedValue 但是显示的值该怎么得到
求大神告知...
谢谢
...全文
298 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
安静9527 2016-08-24
  • 打赏
  • 举报
回复
引用 2 楼 hai_na_bai_chuan_ 的回复:
忘了给你样式中的事件 List<CheckBox> CheckList = new List<CheckBox>(); private void CheckBox_Click(object sender, RoutedEventArgs e) { if ((sender as CheckBox).IsChecked == true) { CheckList.Add(sender as CheckBox); } else { CheckList.Remove(sender as CheckBox); } }
已经做好了 用的最笨的方法 写一个方法 把value的值 根据逗号分割 在进行匹配在把所有匹配的值返回...
hai_na_bai_chuan_ 2016-08-18
  • 打赏
  • 举报
回复
忘了给你样式中的事件 List<CheckBox> CheckList = new List<CheckBox>(); private void CheckBox_Click(object sender, RoutedEventArgs e) { if ((sender as CheckBox).IsChecked == true) { CheckList.Add(sender as CheckBox); } else { CheckList.Remove(sender as CheckBox); } }
hai_na_bai_chuan_ 2016-08-18
  • 打赏
  • 举报
回复
定义样式: <controls:ChildWindow.Resources> <Style x:Key="comboxStyle1" TargetType="ComboBoxItem"> <Setter Property="Background" Value="Yellow"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBoxItem"> <CheckBox Content="{TemplateBinding Content}" Click="CheckBox_Click"></CheckBox> </ControlTemplate> </Setter.Value> </Setter> </Style> </controls:ChildWindow.Resources> <ComboBox x:Name="tbcn" DropDownClosed="tbcn_DropDownClosed" DropDownOpened="tbcn_DropDownOpened"> 生成控件: foreach (string t in e.Result.ToList()) { ComboBoxItem item = new ComboBoxItem(); item.Content = t; item.Style = this.Resources["comboxStyle1"] as Style; tbcn.Items.Add(item); } 获取值: private string deptlist; private void tbcn_DropDownClosed(object sender, EventArgs e) { string name = ""; foreach (var one in CheckList) { name += one.Content + ","; deptlist += "'" + one.Content + "',"; } tbcn.Items.Add(new ComboBoxItem() { Content = name.ToString() }); tbcn.SelectedIndex = tbcn.Items.Count - 1; } private void tbcn_DropDownOpened(object sender, EventArgs e) { if (tbcn.Items.Count >0 ) tbcn.Items.RemoveAt(tbcn.Items.Count - 1); deptlist = ""; }

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧