此功能在以前的 .NET 中是否可用
我正在查看 Charles Petzold 的一些代码,他正在使用以下内容PropertyChangedCallback
的语法
public static readonly DependencyProperty CenterProperty =
EllipseGeometry.CenterProperty.AddOwner(
typeof(CenteredEllipse),
new FrameworkPropertyMetadata(new Point(0, 0),
EllipsePropertyChanged));
如果您这样做,则不起作用,您需要将属性更改回调放入 new new PropertyChangedCallback(EllipsePropertyChanged)
。他也在直接编辑变量:
void EllipsePropertyChanged(DependencyPropertyChangedEventArgs args)
{
elipGeo.Center = Center;
elipGeo.RadiusX = RadiusX;
elipGeo.RadiusY = RadiusY;
InvalidateMeasure();
}
应该是这样的:
static void EllipsePropertyChnaged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
EllipseGoemetry ellipseGeo = (EllipseGoemetry )obj;
args.newValue ...
}
有人知道发生了什么事吗?
I am looking at some code from Charles Petzold, he is using the following syntax for PropertyChangedCallback
public static readonly DependencyProperty CenterProperty =
EllipseGeometry.CenterProperty.AddOwner(
typeof(CenteredEllipse),
new FrameworkPropertyMetadata(new Point(0, 0),
EllipsePropertyChanged));
It doesn't work if you do it this way you need put the property changed callback in new new PropertyChangedCallback(EllipsePropertyChanged)
. He is also editing the variables directly:
void EllipsePropertyChanged(DependencyPropertyChangedEventArgs args)
{
elipGeo.Center = Center;
elipGeo.RadiusX = RadiusX;
elipGeo.RadiusY = RadiusY;
InvalidateMeasure();
}
Should it be something like this:
static void EllipsePropertyChnaged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
EllipseGoemetry ellipseGeo = (EllipseGoemetry )obj;
args.newValue ...
}
Does someone know what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个是委托类型推断的示例。从此: http: //blogs.msdn.com/b/noahc/archive/2008/09/23/delegate-type-inference-in-c.aspx
The first one is an example of Delegate Type Inference. From this: http://blogs.msdn.com/b/noahc/archive/2008/09/23/delegate-type-inference-in-c.aspx
elipGeo
被定义为类的一个字段,该代码是正确的。您不需要从方法显式创建委托,这是隐式完成的,此功能是在 C# 2.0 中添加的。
elipGeo
is defined as a field of the class, that code is correct.You do not need to explicity create delegates from methods, that is done implicitly, this feature was added in C# 2.0.
问题是他对两个方法使用相同的名称,因此可能会造成混淆:
第一个是委托,第二个只是该类的一个方法,他在委托中调用该方法,在其中强制转换 obj,只是正如它应该做的那样。
The thing is that he uses the same names for two method so it can get confusing:
The first one is the delegate, the second one is just a method of the class, which he is calling in the delegate, where he casts obj, just as it supposed to be done.