【发布时间】:2012-07-12 02:00:22
【问题描述】:
我正在使用 wpf 并多重绑定到 ViewModel 列表。
假设我有一个相同类型的 ViewModel 的 ObservableCollection,如下所示:
代码:
public class ShapeVM
{
public Color Color { get; set; }
public string Name { get; set; }
}
ObservableCollection ShapeVMs = new ObservableCollection();
ShapeVMs.Add(...);
ShapeVMs.Add(...);
ShapeVMs.Add(...);
ShapeVMs.Add(...);
ShapeVMs.Add(...);
// There are 5 ShapeVM in the collection.
查看:
<UserControl .........>
<ColorBox SelectedColor="{Binding Path=Color, Mode=TwoWay}" />
</UserControl>
是否有可能每当ColorBox的SelectedColor发生变化时,5个ShapeVM的Color会同时自动变为ColorBox的SelectedColor?
如果我将 UserControl 的 DataContext 设置为任一 ShapeVM,则仅更改任一 ShapeVM 的颜色。
但是,我想在 ColorBox 的 SelectedColor 更改的同时更改 5 个 ShapeVM。我怎么能这样做?
非常感谢。
【问题讨论】:
标签: wpf binding observablecollection