我有两个TextBox( XAML )
<s:SurfaceTextBox Name="CodePostal" TextChanged="CodePostalChanged" />
<s:SurfaceTextBox Name="Commune" Text="{Binding Path=CommuneGeographique}" />
在( .cs文件)
中private MyModelContainer db;
private ObservableCollection<Commune> _CommunesList = new ObservableCollection<Commune>();
private ObservableCollection<Commune> CommunesList
{
get { return _CommunesList; }
set { _CommunesList = value; }
}
在构造函数中,我有:
InitializeComponent();
getCommunes("Test");
getCommunes(字符串搜索),是Linq查询
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;
此时一切正常,Commune TextBox显示我想要的内容。
我的问题是当我尝试在TextChanged上调用getCommunes()方法
private void CodePostalChanged(object sender, TextChangedEventArgs textChangedEventArgs)
{
getCommunes("Toto");
}
没有任何反应,TextBox被清除。
(它应显示其他内容,但即使CommuneList有元素也是空的)
答案 0 :(得分:0)
因为你没有用好的属性绑定你的文本框,CommuneGeographique?
<s:SurfaceTextBox Grid.Column="1" Name="Commune" Text="{Binding Path=CommuneGeographique}" />