大佬教程收集整理的这篇文章主要介绍了silverlight自定义用户控件,实现下拉多选功能,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
XAML:
<Grid x:Name="LayoutRoot" BACkground="White">
<ComboBox x:Name="chkTest" MinHeight="20"
DropDownOpened="chktest_DropDownOpened" DropDownClosed="chktest_DropDownClosed">
</ComboBox>
</Grid>
后台代码:
public partial class MilutSELEct : UserControl
{
private String _SELEctValue;
/// <sumMary>
/// 选择的值
/// </sumMary>
public String SELEctValue
{
get { return _SELEctValue; }
}
public MilutSELEct()
{
InitializeComponent();
}
/// <sumMary>
/// 设置选择项
/// </sumMary>
/// <param name="values"></param>
public void SetSELEctValue(IList<String> values)
{
checkList.Clear();
if (values != null && values.Count > 0)
{
_SELEctValue = String.Join(",",values);
if (chkTest.Items != null && chkTest.Items.Count > 0)
{
foreach (var item in chkTest.Items)
{
if (item is checkBox)
{
var ck = item as checkBox;
if (values.Contains(ck.Content.ToString()))
{
ck.Ischecked = true;
checkList.Add(ck);
}
}
}
}
}
bindCalues();
}
/// <sumMary>
/// 数据绑定
/// </sumMary>
/// <param name="datasource"></param>
public void BindDatasource(IList<String> datasourcE)
{
if (datasource != null && datasource.Count > 0)
{
IList<ComboBoxItem> list=new List<ComboBoxItem>();
foreach (var item in datasourcE)
{
var bi = new checkBox { Content = item};
bi.Click += checkBox_Click;
chkTest.Items.Add(bi);
}
chkTest.Items.Add(new ComboBoxItem());
}
}
private 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);
}
}
private void chktest_DropDownOpened(object sender,EventArgs E)
{
chkTest.Items.RemoveAt(chkTest.Items.Count - 1);
}
private void chktest_DropDownClosed(object sender,EventArgs E)
{
bindCalues();
}
private void bindCalues()
{
String name = "";
foreach (var one in checkList)
{
NAME += one.Content + ",";
}
if (name.Length > 0)
NAME = name.Remove(name.Length - 1);
chkTest.Items.Add(new ComboBoxItem() { Content = name.ToString() });
_SELEctValue = name;
chkTest.SELEctedIndex = chkTest.Items.Count - 1;
}
}
调用时:
页面引用用户控件,x:name:msl
以上是大佬教程为你收集整理的silverlight自定义用户控件,实现下拉多选功能全部内容,希望文章能够帮你解决silverlight自定义用户控件,实现下拉多选功能所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。