开发者

How to prevent a combobox from selecting an item from its list in wpf?

开发者 https://www.devze.com 2022-12-08 15:27 出处:网络
This combobox should display a bound value as its text, and cannot be disabled. I just want to prevent a user from changing the displayed va开发者_JS百科lue.

This combobox should display a bound value as its text, and cannot be disabled. I just want to prevent a user from changing the displayed va开发者_JS百科lue.


    comboBoxName.IsHitTestVisible = false;
    comboBoxName.Focusable = false;

Use these two line codes together.

Edit Note: Edited to solve the problem described by skypecakes


Accoring to MSDN you need

IsReadOnly = true;
IsEditable = false;

See http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.isreadonly.aspx under Remarks

Edit: actually, I'm not sure any more

I suggest using a style to set ReadOnly to true on PART_EditableTextBox


Try in XAML

IsEnabled="False"

C#

YOUCOMBOBOX.IsEnabled=false;


If you set the IsEnabled = false this should work. In your XAML it would look like this

<ComboBox IsEnabled="False"></ComboBox>


Your question is unclear.

A combobox has the dependency property IsEditable and if set to false, the selected item can not be edited. This is false by default.

If you are talking about the items in the combobox popup list, then it should also be "non editable" unless you have changed the data template of your combo box to contain a list of textboxes which will cause the list to allow each item to be editable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号