WPF 依赖属性返回值
我对 WPF 还很陌生。
假设我定义了一个 int 依赖属性。 DP 的目的是返回值+1(参见代码)。 在 .Net 2.0 中,我会这样写:
private int _myValue = 0;
public int MyValue
{
get { return _myValue + 1; }
set { _myValue = value; }
}
How would you suggest a DP that Achieves like behavior?
提供的强制仅适用于 Set 操作。 我想修改获取结果。
I'm fairly new to WPF.
Suppose I defined an int dependency property. The purpose of the DP is to return the value+1 (see code).
In .Net 2.0 I would have written:
private int _myValue = 0;
public int MyValue
{
get { return _myValue + 1; }
set { _myValue = value; }
}
How would you declare a DP that achieves similar behavior?
The Coercion that was offered works only for the Set operation. I would like to modify the Get result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样间接实现它:
检查此 链接 有关强制的解释。
You would achieve it indirectly like this:
Check this link for an explanation about coercion.