【发布时间】:2012-04-02 22:01:02
【问题描述】:
我是一个包含此方法的 WCF 服务:
public List<LocationDB> GetLocation()
{
List<LocationDB> locations = null;
using (SqlConnection connection = new SqlConnection(conn))
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandText = string.Format("Select L_ID ,L_Name from Location");
connection.Open();
//code to fill the locations list..
我的问题是当我想在我的代码中绑定此方法的结果时,我会执行以下操作。
void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
client.GetLocationCompleted += new EventHandler<GetLocationCompletedEventArgs>(client_GetLocationCompleted);
client.GetLocationAsync();
}
}
和:
void client_GetLocationCompleted(object sender, GetLocationCompletedEventArgs e)
{
LocationCombo.ItemsSource = e.Result;
LocationCombo.SelectedValuePath =
LocationCombo.DisplayMemberPath =
}
最后是位于 asp 网站 App_code 文件夹中的 LocationDB 类:
[DataContract]
public class LocationDB
{
[DataMember]
public int Lid { get; set; }
[DataMember]
public int SmId { get; set; }
[DataMember]
public string Lname { get; set; }
如何将 SelectedValePath 和 DisplayMemberPath 绑定在代码后面而不是 XAML 中。 谢谢
【问题讨论】:
标签: c#-4.0 data-binding silverlight-4.0