WPF/C# Combobox Only Changes Selection When A Click is Detected Outside of Text Area -
so have several comboboxes in wpf application don't change selection when user clicks on text of combobox item. in order select particular item have click right or left of text. have combobox selects fine when text clicked. difference between 2 databinding. comboboxes don't select when text clicked databound observablecollection of 1 type or another. combobox works has manually inserted, static values.
i've searched issue extensively , can't seem find else has had issue or remotely similar. i'm not setting weird properties.
here code 1 of problematic comboboxes:
<combobox horizontalalignment="left" margin="40,160,0,0" verticalalignment="top" width="132" itemssource="{binding path=systems}" selecteditem="{binding path=system}" selectedindex="0"> <combobox.itemtemplate> <datatemplate> <comboboxitem content="{binding path=name}"/> </datatemplate> </combobox.itemtemplate> </combobox>
here video of behavior:
enter code here
suppose combobox defind below
<combobox name="cmb" width="200" height="20" displaymemberpath="personname" selectedvaluepath="personid"> </combobox>
please notice , have removed itemtemplate part
and model below
public class person { public string personname { get; set; } public string personid { get; set; } }
and binding in code behind , step not necessary , can in xaml , iam checking dirty code
public list<person> source = new list<person>(); public mainwindow() { initializecomponent(); (int = 0; < 20; i++) { source.add(new person() { personid = i.tostring(), personname = "sau" + i.tostring() }); } cmb.itemssource = source; this.datacontext = this; }
so if run sample , see can select value when click on text itself.
it's content property causes problem not 100% sure on this.
Comments
Post a Comment