【发布时间】:2015-10-31 19:31:40
【问题描述】:
在我的应用程序中,我使用 PropertyGrid 来设置与加载数据、设置场景等相关的属性。不过,在使用 Vector3 作为属性时,我遇到了一个小问题。事实证明,如果我尝试使用 OpenTK Vector3 结构作为 PropertyGrid 的字段,它会停用该字段(它显示为灰色且无法更改)。我假设这是由于结构是不可变的,因此无法编辑。我想知道是否有办法解决这个问题。我知道我可以将自己的 Vector3 定义为一个可以工作的类,但我想继续使用 OpenTK Vector3。
这是我的应用程序的屏幕截图:
这里是 PropertyGrid 设置类:
using System.ComponentModel;
using OpenTK;
using StardustModeling.Modeling.IOFilters;
namespace StardustModeling.Modeling
{
public class ModelBuilderSceneSettings
{
[Description( "The name of the compiled model." ),
Category( "Information" )]
public string Name { get; set; } = "";
[Description( "The geometry data for the model." ),
Category( "Data" ),
Editor(
typeof( WavefrontModelFilter ) ,
typeof( System.Drawing.Design.UITypeEditor ) )]
public string GeometryMesh { get; set; } = "";
[Description( "The Diffuse Texture of the model." ),
Category( "Texturing" ), Editor(
typeof( BitmapFilter ) ,
typeof( System.Drawing.Design.UITypeEditor ) )]
public string Diffuse { get; set; } = "";
[Description( "The NormalMap for the model." ),
Category( "Texturing" ), Editor(
typeof( BitmapFilter ) ,
typeof( System.Drawing.Design.UITypeEditor ) )]
public string Normals { get; set; } = "";
[Description( "Position of the scene lamp." ),
Category( "Scene" )]
public Vector3 Lamp { get; set; } = new Vector3(2,2,2);
[Description( "Model Position." ),
Category( "Scene" )]
public Vector3 ModelLocation { get; set; } = new Vector3(); // Default 0,0,0
}
}
【问题讨论】:
-
为什么要关闭投票?这是一个有效的问题。
-
您可以访问
Vector3定义吗?检查它是否有关联的TypeConverter,例如 [System.Drawing.Point](referencesource.microsoft.com/#System.Drawing/commonui/System/…) -
@IvanStoev 它没有:github.com/opentk/opentk/blob/develop/Source/OpenTK/Math/…
-
那你就得自己写了。您可以将此作为示例referencesource.microsoft.com/#System.Drawing/commonui/System/…。然后只需使用属性将其与您的属性相关联。我认为这比上面提供的 SO 链接中的实现更好。
标签: c# propertygrid