我正在使用下面的Datagrid(使用MVVM模式),在這裏我想要的是當我選擇組合框中的某些東西時,應該在ViewModel中發生某種通知,說該行的組合框selectedItem被更改爲這個值。現在通知發生在SelectedEname的Set方法中,該方法位於類SortedDetails(自定義實體)內部,而不是viewmodel的一部分。請查看下面的代碼,並讓我知道如果我們可以使用MVVM模式以任何方式將通知發送到videmodel。Binding Combobox列的selectedItem屬性Silverlight MVVM
<c1:C1DataGrid x:Name="datagrid1" ItemsSource="{Binding Path=SortedDetailsList,Mode=TwoWay}" AutoGenerateColumns="False">
<c1:C1DataGrid.Columns>
<c1:DataGridTextColumn Header="Name" Binding="{Binding Name, Mode=TwoWay}"/>
<c1:DataGridTemplateColumn Header="ENGAGEMENT">
<c1:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="cmbEngagement" ItemsSource="{Binding EDetails, Mode=TwoWay}" DisplayMemberPath="EName" SelectedItem="{Binding SelectedEName,Mode=TwoWay}">
</ComboBox>
</DataTemplate>
</c1:DataGridTemplateColumn.CellTemplate>
</c1:DataGridTemplateColumn>
</c1:C1DataGrid.Columns>
</c1:C1DataGrid>
SortedDetailsList是SortedDetails實體的名單,它看起來像這樣: -
public class SortedDetails
{
Private string name;
Private ObservableCollection<details> eDetails;
Private details selectedEname;
public string Name
{
get { return name; }
set { name = value; }
}
public ObservableCollection<details> EDetails
{
get { return eDetails; }
set { eDetails = value; }
}
public details SelectedEname
{
get { return selectedEname; }
set { selectedEname = value; }
}
}
public class Details
{
Private string eName;
Private int eId;
public string EName
{
get { return eName; }
set { eName = value; }
}
public int EId
{
get { return eId; }
set { eId = value; }
}
}