Я пытаюсь привязать данные к ComboBox с помощью WCF RIA.Только для привязки данных это хорошо, но в то же время я хочу быть уже выбранным для указанного элемента после привязки.Для этого случая я не знаю, как я могу сделать, чтобы достичь этого.Может быть так, что моя привязка данных также неверна.
Вот моя сущность
public class Customer
{
[System.ComponentModel.DataAnnotations.Key()]
public int CustomerId { get; set; }
public string CustomerName { get; set; }
}
Вот служба WCF RIA
public class CustomerDomainService : DomainService
{
public IEnumerable<Customer> GetCustomers()
{
List<Customer> rtnList = new List<Customer>();
DataTable dt = (new CustomerBLL()).GetAllCustomers;
foreach (DataRow dr in dt.Rows) {
rtnList.Add(new Customer {
CustomerId = Convert.ToInt32(dr("CustomerID")),
CustomerName = Convert.ToString(dr("CustomerName"))
});
}
return rtnList;
}
}
Вот XAML
<ComboBox Name="CustomerComboBox" HorizontalAlignment="Left" Height="25" Width="150" Grid.Column="1" Grid.Row="1" ItemsSource="{Binding ElementName=CustomerDomainDataSource, Path=Data}" DisplayMemberPath="CustomerName" SelectedValuePath="CustomerId"/>
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Customer, CreateList=true}" Height="0" Name="CustomerDomainDataSource" QueryName="GetCustomersQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:CustomerDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
С уважением