C# 集合中的换行列表是否使其成为只读?
我有一个数据库控制器类,它创建了两个表适配器和一个数据集。此外,我还为每个表行创建了一个模型,并为每一行创建了一个带有模型实例的ObservableCollectionC# 集合中的换行列表是否使其成为只读?,c#,wpf,collections,binding,C#,Wpf,Collections,Binding,我有一个数据库控制器类,它创建了两个表适配器和一个数据集。此外,我还为每个表行创建了一个模型,并为每一行创建了一个带有模型实例的ObservableCollection private ObservableCollection<DoubleTeamModel> _doubleTeams = new ObservableCollection<DoubleTeamModel>(); foreach (UsersDataSet.Double_TeamsRow row in ds
private ObservableCollection<DoubleTeamModel> _doubleTeams = new ObservableCollection<DoubleTeamModel>();
foreach (UsersDataSet.Double_TeamsRow row in ds.Double_Teams)
{
_doubleTeams.Add(new DoubleTeamModel(row));
}
网格应该是writeable Mode=TwoWay,但每个假定为只读的列的模式都设置为OneWay。根据异常情况,整个集合什么时候变成只读的?这意味着您的属性只有getter而没有setter,但是您尝试同时绑定这两种方式,但是我不需要这些属性的setter。我应该为了绑定而创建一个,还是有其他/更智能的方法?为什么需要双向绑定?DataGrid不会更改其ItemsSourceWell,我确实绑定到每个项目的各个属性,理论上网格中的更改意味着项目中的更改,而不是ItemsSource。我会试试的,谢谢如果这就是你想要的,那么你就不需要为了DataGrid双向工作而绑定ItemsSource。您针对列绑定或针对整个DataGrid或列使用IsReadOnly指定的位。
public BindingList<TeamMatchModel> TeamQualificationMatches
{
get
{
return new BindingList<TeamMatchModel>(App.Data.GetDoubleTeamMatches().Where(
match => match.TournamentId == CurrentTournament.Id &&
match.Status == MatchStatus.QualificationsPlaying).ToList<TeamMatchModel>());
}
}
<DataGrid x:Name="dgrTeamQualificationMatches" AutoGenerateColumns="False" Margin="5,10,5,10"
ItemsSource="{Binding TeamQualificationMatches, Mode=TwoWay}"
CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False"
SelectionMode="Single" SelectionUnit="FullRow"
RowStyle="{DynamicResource EditableRows}" CellStyle="{DynamicResource EditableTableCells}">
<DataGrid.Columns>
<DataGridTextColumn Header="Team A" Binding="{Binding TeamANames, Mode=OneWay}"
CellStyle="{DynamicResource ScoreATableCells}" Width="Auto" />
<DataGridTemplateColumn Header="Highest shot 1" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding TeamANameA}" />
<TextBox Text="{Binding HighestShotTeamAPlayerA, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
// Some other columns
</DataGrid.Columns>
</DataGrid>
A TwoWay or OneWayToSource binding cannot work on the read-only property 'TeamQualificationMatches' of type 'CompetitionAgent.ViewModel.TournamentViewModel'