具有可选成员的属性网格最佳方法
我有一个属性网格对象,要求您选择一个枚举,例如,您有:
enum XScalingType { ShowAll, Fixed, Sigma }
现在,基于此枚举选择,我们只关心某些参数。即:
ShowAll - requires none
Fixed - double Minimum, double Maximum
Sigma - double Sigma
这给我留下了下面的课程,
class MyPrefs
XScalingType XScale
double minimum //only matters when XScale = Fixed
double maximum //only matters when XScale = Fixed
double Sigma //only matters when XScale = sigma
我不知道如何从这里继续。我的想法是,我需要将 min\max\sigma 设置为所有成员,如果不使用它们,则将它们隐藏在网格中。
然而,这似乎并不常见。是否有更正式的方法来根据其他枚举选择使用这些可选参数?
我想知道我是否完全从错误的方向处理这个问题。
I have a property grid object that requires you to choose an enum, for example, you have:
enum XScalingType { ShowAll, Fixed, Sigma }
Now, based on this enum selection, we only care about certain parameters. Namely:
ShowAll - requires none
Fixed - double Minimum, double Maximum
Sigma - double Sigma
This leaves me with the following class
class MyPrefs
XScalingType XScale
double minimum //only matters when XScale = Fixed
double maximum //only matters when XScale = Fixed
double Sigma //only matters when XScale = sigma
I'm not sure how to proceed from here. My thoughts where, I need to make min\max\sigma all members, and just hide them from the grid if they aren't used.
However, that doesn't seem like common practice. Is there a more formal way to use these optional parameters based on other enum selections?
I'm wondering if I'm approaching this from the wrong direction completely.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更好的方法是创建状态感知属性访问器,如下所示:
然后,如果 XScale 不是 Sigma,则属性 Sigma 将显示为空。
A better approach is to create state-aware property accessors like the following:
then if XScale is anything other than Sigma, the property Sigma will show empty.