本文介绍了Silverlight中的ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除组合框中的选定值而不删除列表中的任何值.

How to clear a selected value in combo box without deleting any value in the list.

推荐答案

DropDownList1.SelectedIndex=-1;


ComboBox1.SelectedIndex = -1 



或您想在Viewmodel中使用它,

然后为所选项目设置属性.并将其设置为null:

例如:



or dou you want it in viewmodel,

then Have a property for selected item. and set it to null:

For eg:

public List<gender> GenderList
{get;set;}


//包括通知属性已更改的属性..以上只是大纲

然后拥有一个属性


//include notify property changed for that property..the above one is just outline

Then have a property

Public Gender SelectedGender
{get;set;}


将Itemsource绑定到GenderList属性,并将Selectedvalue属性绑定到SelectedGender.

每当您想清除选择Set SelectedGender = null时.因为那里有Notifyproperty更改的元素,它将清除选择


Bind Itemsource to GenderList property and Selectedvalue property to SelectedGender.

Whenever You want to clear the selection Set SelectedGender =null. SInce Notifyproperty changed element is there, it will clear the selection


这篇关于Silverlight中的ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:40