【问题标题】:.NET Using a Struct within a PropertyGrid [duplicate].NET 在 PropertyGrid 中使用结构 [重复]
【发布时间】: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
    }
}

【问题讨论】:

标签: c# propertygrid


【解决方案1】:

一个快速的解决方法,虽然不是我想要的,但是使用字符串来代替,格式为“x,y,z”,并在编辑字段时将其转换为 Vector3。我认为这就是 Visual Studio 对其某些领域所做的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-22
    • 2012-05-01
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多