标签: propertygrid

如何在自定义控件的属性网格中获取OpenFileDialog?

我正在创建.net自定义控件,它应该能够加载多个文本文件.我有一个名为ListFiles的公共属性,其中包含以下属性:


[Browsable(true), Category("Configuration"), Description("List of Files to Load")]
public string ListFiles
  {
     get { return m_oList; }
     set { m_oList = value; }
  }
Run Code Online (Sandbox Code Playgroud)

根据对象的类型(string,string [],List,...),属性网格将允许用户输入一些数据.我的目标是在我的组件的属性网格中有一个过滤的openfiledialog这将使用户能够选择多个文件并将其作为数组或字符串(或其他东西......)返回.

Sooo ...这是我的问题:如何在自定义控件的属性网格中获得OpenFileDialog?

非常感谢!

.net c# propertygrid controls

9
推荐指数
2
解决办法
9436
查看次数

获取类型的默认PropertyDescriptors

我正在PropertyGrid通过实现自定义对象类型的显示方式ICustomTypeDescriptor.我允许用户创建自己的自定义属性,这些属性存储在单个键和值字典中.我能够PropertyDescriptors为这些值创建所有值并在属性网格中查看它们.但是,我还想显示所有默认属性,如果PropertyGrid通过反射填充而不是覆盖ICustomTypeDescriptor.GetProperties方法,则会显示这些属性.

现在我知道如何获取对象的类型,然后GetProperties(),但这会返回一个PropertyInfonot 数组ProperyDescriptor.那么如何PropertyInfo将该类型的对象转换为PropertyDescriptor对象以包含到我的集合中PropertyDescriptors

//gets the local intrinsic properties of the object
Type thisType = this.GetType();
PropertyInfo[] thisProps = thisType.GetProperties();

//this line obviously doesn't work because the propertydescriptor 
//collection needs an array of PropertyDescriptors not PropertyInfo
PropertyDescriptorCollection propCOl = 
    new PropertyDescriptorCollection(thisProps);
Run Code Online (Sandbox Code Playgroud)

c# propertygrid propertyinfo propertydescriptor

9
推荐指数
1
解决办法
8229
查看次数

如何为闭源类型的所有属性注入自定义UITypeEditor?

我想避免在我编写自定义UITypeEditor的某个类型的每个实例上放置EditorAttribute.

我不能在类型上放置EditorAttribute,因为我无法修改源代码.

我引用了将要使用的唯一PropertyGrid实例.

我是否可以告诉PropertyGrid实例(或所有实例)在遇到特定类型时使用自定义UITypeEditor?

是一篇MSDN文章,它提供了如何在.NET 2.0或更高版本中执行此操作的起点.

.net c# propertygrid uitypeeditor

9
推荐指数
1
解决办法
8354
查看次数

使用Xceed PropertyGrid

我是C#/ WPF的初学者,我正在尝试使用Xceed PropertyGrid.在他们的网站上他们展示了一个例子

 <xctk:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10"
                                 AutoGenerateProperties="False">
            <!-- Only the following properties will be displayed in the PropertyGrid -->
            <xctk:PropertyGrid.PropertyDefinitions>
                <xctk:PropertyDefinition Name="FirstName" />
                <xctk:PropertyDefinition Name="FavoriteColor" />
                <xctk:PropertyDefinition Name="PetNames" />
            </xctk:PropertyGrid.PropertyDefinitions>
        </xctk:PropertyGrid>
Run Code Online (Sandbox Code Playgroud)

我插入到我的xaml中.我看到了PropertyGrid View但是我没有看到任何属性定义.我觉得我必须遗漏一些基本的东西?我应该在代码隐藏中添加任何内容吗?

wpf propertygrid xceed

9
推荐指数
1
解决办法
1万
查看次数

更改PropertyGrid中属性项的值

在下图中,"MyCars"是一个集合.如果对象的属性是集合,则在PropertyGrid中,如果选择了该项,则该值将显示为字符串"(Collection)",并带有右侧的按钮.

是否可以更改"(收集)"值?如果是这样,怎么样? 我问的原因是因为我已经为我的程序中的PropertyGrid中出现的对象实现了一个自定义UITypeEditor.到目前为止,右侧的按钮出现,但文本值与属性的显示名称相同.我想在那里出现一个不同的字符串.

示例propertygrid.

编辑:对于什么是值得的,我知道我可以覆盖PaintValue从UITypeEditor的方法,并提供一个图标,我最终可能会,如果我解决不了这个问题,这样做,但我还是想知道是否以及如何"(集合)"文本可以更改.

c# propertygrid winforms

9
推荐指数
1
解决办法
2415
查看次数

更新PropertyGrid

当SelectedObject属性中的对象发生更改时,如何自动更新属性网格?我已经尝试在我的类中实现INotifyPropertyChanged,但属性网格实际上并没有在后台显示对象的新属性,直到我点击它.

我已经尝试直接订阅我的对象的PropertyChanged事件,并在调用它时调用PropertyGrid的Refresh()方法.但是我的一些房产是相关的.更改一个属性的含义可能会引发多个PropertyChanged事件.这似乎工作正常,但我仍然想知道是否有更简洁的方法通过DataBinding这样做.另外,我想在用户仅更新单个属性后避免多次使用控件Refresh.

那么有没有办法让PropertyGrid从PropertyChanged事件中刷新?

c# data-binding propertygrid inotifypropertychanged winforms

8
推荐指数
2
解决办法
9845
查看次数

是否有我可以在我的WPF应用程序中使用的属性对话框控件?

我正在使用WPF构建一个应用程序,它将成为各种设计者,这意味着,用户可以将自定义UI元素拖放到画布中,并能够通过属性配置其行为.

(将此视为特定于域的PowerPoint.您可以向演示文稿添加元素,配置元素的属性,然后最终可以运行"幻灯片放映",这些元素将根据其属性运行)

所以在我的应用程序中,显示和配置元素属性的最佳方法是什么?我可以使用属性对话框控件吗?(类似于Visual Studio中的控件)

.net wpf propertygrid controls properties

8
推荐指数
1
解决办法
6046
查看次数

如何创建自定义集合编辑器表单以与属性网格一起使用?

我试图将属性网格控件与一个类相结合,该类具有另一个类的列表/集合作为其中一个属性.让我们称它们为A类,列表将包含B类以供参考.

我想要合并一个有两个列表框的表单.左侧的列表框将包含我的程序中当前不在右侧列表中的所有B类的列表.右边的列表将包含当前与A类关联的所有B类.我希望两者之间的按钮在两个列表之间移动项目.

这很容易设计,但我不确定如何设置表单以用作集合编辑器.

谁能指出我正确的方向?

而且,我如何设置一个包含可供选择的ID列表的属性的下拉列表,如果有人可以指出我的方向来完成这个.

.net c# propertygrid collectioneditor

8
推荐指数
1
解决办法
8268
查看次数

PropertyGrid对象级别的readonly属性

我想在我的中显示一个类的多个实例PropertyGrid.这个类看起来像这样:

public class Parameter
{
    [Description("the name")]
    public string Name { get; set; }

    [Description("the value"), ReadOnly(true)]
    public string Value { get; set; }

    [Description("the description")]
    public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我有很多类的实例TreeView.当我在我选择其中一个时TreeView,属性会PropertyGrid按预期显示.到目前为止一切顺利,但我想以下列方式自定义此行为:

对于每个单个实例,我希望能够阻止用户修改特定属性.通过ReadOnly(true)在我的类中设置(如上面的示例中所示),Value将在类级别禁用所有属性.

经过一些研究后,我发现以下解决方案让我有机会在运行时启用/禁用特定属性:

PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this)["Value"];

ReadOnlyAttribute attr = 
        (ReadOnlyAttribute)descriptor.Attributes[typeof(ReadOnlyAttribute)];

FieldInfo isReadOnly = attr.GetType().GetField(
        "isReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);

isReadOnly.SetValue(attr, false);
Run Code Online (Sandbox Code Playgroud)

这种方法运行得很好但不幸的是也只​​在类级别上.这意味着,如果我设定ValueisReadOnlyfalse,所有我的Parameter-objects拥有 …

.net c# propertygrid propertydescriptor readonly-attribute

8
推荐指数
1
解决办法
1万
查看次数

如何在winform c#中更改另一个项目时更新propertygrid项目值?

我有一个属性网格有2个项目.国家和城市.我在数据库中有1个表:CountryCityTable保存LocationId,Title,ParentId.对于国家,parentId = 0,而对于城市,则为countryid.

在我的propertygrid中,我使用这些并在2个组合框项目中显示.请看我的代码:

namespace ProGrid
{
    public class KeywordProperties
    {
        [TypeConverter(typeof(CountryLocationConvertor))]
        public string CountryNames { get; set; }

        [TypeConverter(typeof(CityLocationConvertor))]
        public string CityNames { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

namespace ProGrid
{
    public class CountryLocationConvertor : StringConverter 
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {            
            HumanRoles Db = new HumanRoles();
            List<LocationsFieldSet> Items = new List<LocationsFieldSet>();
            Items = Db.LoadLocations(0,0);
            string[] LocationItems = new string[Items.Count];
            int count = 0;
            foreach (LocationsFieldSet Item in …
Run Code Online (Sandbox Code Playgroud)

c# propertygrid

8
推荐指数
1
解决办法
4639
查看次数