I'm have two TextBoxes (XAML)
<s:SurfaceTextBox Name="CodePostal" TextChanged="CodePostalChanged" />
<s:SurfaceTextBox Name="Commune" Text="{Binding Path=CommuneGeographique}" />
And in the (.cs file)
private MyModelContainer db;
private ObservableCollection<Commune> _CommunesList = new ObservableCollection<Commune>();
private ObservableCollection<Commune> CommunesList
{
get { return _CommunesList; }
set { _CommunesList = value; }
}
In the constructor, I have this :
InitializeComponent();
getCommunes("Test");
And getCommunes(string search), is a Linq query
db = new MyModelContainer();
CommunesList.Clear();
Commune.DataContext = _CommunesList;
var myCommunes = from d in db.Communes
where d.CommunePostale.Equals(search)
select d;
foreach (Commune c in myCommunes)
{
CommunesList.Add(c);
}
Commune.DataContext = CommunesList;
At this point everything works fine and the Commune TextBox displays what I want.
My problem is that when I try to call the getCommunes() method on a TextChanged
private void CodePostalChanged(object sender, TextChangedEventArgs textChangedEventArgs)
{
getCommunes("Toto");
}
Nothing happens and the TextBox is cleared.
(It should display something else, but its empty even if the CommuneList has an element)