WPF 矩形命令绑定 MVVM
我有以下问题 我有很多矩形(或路径),我想向每个矩形添加一个命令,当我单击矩形时,对象将填充矩形的值(颜色,名称)。并且从 GUI 我当我执行命令时想要改变矩形的颜色 我怎样才能在 MVVM 中做到这一点?
例如我有一个对象 Ractangle
public Class Rectangle{
String name;
String color;
public String Color{
get{ return color;}
set {color=value;}
OnPropertyChange(color);
}
public String Name{
get{ return name;}
set {name=value;}
OnPropertyChange(name);
}
I have the following problem
I have a lot of rectangles(or a paths) and I want to add a command to every rectangle, that when I click the rectangle an object will be fill with the values of the rectangle(color,name).And from the GUI I want to change the color of the rectangle when I execute the command
How can I do that in MVVM?
For example I have an object Ractangle
public Class Rectangle{
String name;
String color;
public String Color{
get{ return color;}
set {color=value;}
OnPropertyChange(color);
}
public String Name{
get{ return name;}
set {name=value;}
OnPropertyChange(name);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果将矩形包装到按钮中会更容易,该按钮为您提供了可以绑定命令的易于使用的命令属性。老实说,虽然我不能 100% 确定您想要什么,但请详细说明您的情况。
I think it would be easier if you wrapped your Rectangle into a Button which gives you the readily usable Command property you can bind a command to. To be honest though I'm not 100% sure what you're after, please elaborate your scenario.