c# - Binding Combobox inside a Listview to a ObservableCollection -
c# - Binding Combobox inside a Listview to a ObservableCollection<string> -
xaml
<usercontrol x:class="patientsinscrit_gmf.listdisplay" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:custom="clr-namespace:patientsinscrit_gmf" datacontext="{binding relativesource={relativesource self}}"> <grid> <grid.rowdefinitions> <rowdefinition height="25"></rowdefinition> <rowdefinition></rowdefinition> </grid.rowdefinitions> <listview grid.row="1" margin="0,0,0,0" x:name ="filelist"> <listview.view> <gridview> <gridviewcolumn header="tag" width="auto"> <gridviewcolumn.celltemplate> <datatemplate> <combobox ></combobox> </datatemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> </gridview> </listview.view> </listview> </grid> </usercontrol>
.cs
namespace patientsinscrit_gmf { public partial class listdisplay : usercontrol { private observablecollection<string> _tags; public observablecollection<string> tags { { homecoming _tags; } } public listdisplay() { initializecomponent(); _tags = new observablecollection<string>(); list<string> tags = facade.instance.retrievetags(); foreach(string s in tags) { _tags.add(s); } } } }
how bind tags combobox, 1 of many columns in listview?
i tried
itemssource = "{binding tags}"
but combobox remains empty. know sure facade list retrieve not empty when it's created add together 2 default tags it's not empty.
i have tried various other solutions found , none working, there code samples not compile.
please help :)
i believe @ time (initially) tags
property fetched, _tags
has not been initialized. after _tags
initialized, can raise tags
property alter (by implementing inotifypropertychanged
). property seems need initialized (changed) once. implementing such interface not necessary. can seek next code ensure @ time tags
fetched, info initialized:
public observablecollection<string> tags { { if(_tags == null){ //move code after initializecomponent() here _tags = new observablecollection<string>(); list<string> tags = facade.instance.retrievetags(); foreach(string s in tags) { _tags.add(s); } } homecoming _tags; } }
in xaml:
<combobox itemssource="{binding tags, relativesource={relativesource ancestortype=usercontrol}}"></combobox>
c# wpf xaml
Comments
Post a Comment