在 C# 代码中将颜色绑定到 Solidbrush.color
我有一个 Cell 类,看起来像这样:
public Color color{get { return colorr; }
set { colorr = value;
if (this.PropertyChanged != null){
this.PropertyChanged(this, new PropertyChangedEventArgs("color"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
我将很多“单元”添加到 viewport3D 中以生成立方体。细胞的颜色会随着时间的推移而变化。所以我的问题是 - 我可以将单元格的颜色绑定到代码中的实体画笔,而不是每次更改时都重新绘制单元格吗?
我有类似的东西,但它不起作用。
Binding b = new Binding();
b.Source = cell.color;
SolidColorBrush solidBrush = new SolidColorBrush();
BindingOperations.SetBinding(solidBrush, SolidColorBrush.ColorProperty, b);
Material material = new DiffuseMaterial(solidBrush);
我现在假设当单元格的颜色改变时,solidBrush 的颜色也会改变,因此 viewport3D 上立方体的颜色也会改变。但事实并非如此。
谢谢 - 大卫
I have a class Cell looking something like this:
public Color color{get { return colorr; }
set { colorr = value;
if (this.PropertyChanged != null){
this.PropertyChanged(this, new PropertyChangedEventArgs("color"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
Im adding a lot of "cell"'s to a viewport3D for generating cubes. And the colors of the cells change as time goes. So my question is - instead of redrawing the cells everytime they change, can I bind a cell's color to a solidbrush in code?
I have something like this, but it wont work.
Binding b = new Binding();
b.Source = cell.color;
SolidColorBrush solidBrush = new SolidColorBrush();
BindingOperations.SetBinding(solidBrush, SolidColorBrush.ColorProperty, b);
Material material = new DiffuseMaterial(solidBrush);
I would suppose now that the color of the solidBrush would change when the cell's color changes, and therefore the color of the cube on the viewport3D changes. But it doesnt.
Thanks
- David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请阅读数据绑定概述和如何调试绑定。
对于
Source
的更改没有绑定更新,如果您想要更新,则需要设置相对于源的Path
。例如,这是因为绑定将订阅
INPC
在源(以及路径上的非叶子)上检查事件报告的名称是否与路径匹配,如果是,则更新目标。
Please read the data binding overview and how to debug bindings.
There are no binding updates to changes of the
Source
, if you want updates you need to set aPath
relative to a source. e.g.This is because the binding will subscribe to
INPC
on the source (and non-leaves on the path) and check if the name reported by the event matches the path, if so the target is updated.