我对如下定义的 WPF (+CaliburnMicro) 列表框有一个奇怪的问题
<GroupBox Header="Configurations" Width="Auto" Grid.Row="1" Grid.Column="2">
<ListBox ItemsSource="{Binding SelectableConfigurations}" BorderThickness="0" Width="Auto">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Path=Name}" IsChecked="{Binding Path=IsSelected}" Margin="15,3" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
</GroupBox>
看来,当我在列表中选择一个项目时,它会修改绑定列表中的项目,但不会在其他地方引用该项目。IE 下面的代码会更新 _selectableConfigurations 列表中的项目,但不会更新附加到 _sc 列表的原始对象。
看来,当属性被修改时,原始对象在列表中被替换,而不是简单地更新。是这样吗?
private readonly List<SelectableConfiguration> _selectableConfigurations;
private ISelectableConfigurations _sc;
public ConfigurationTabViewModel(
ISelectableConfigurations configurations)
{
_sc = configurations;
_selectableConfigurations = configurations.SelectableConfigurations.ToList();
}
public List<SelectableConfiguration> SelectableConfigurations
{
get { return _selectableConfigurations; }
}
编辑
public class SelectableConfiguration
{
public bool IsSelected { get; set; }
public string Name { get; set; }
public IRunableOrmConfiguration Configuration { get; set; }
}