如何ObservableCollection<>
在Xceed WPF PropertyGrid中显示一个自定义对象,其中每个List Item都可以展开以显示自定义对象属性.(即:
---- ----- PropertyGrid的
CoreClass
(+/-)ObservableCollection <CustomClass>
(+/-)CustomClass.Object1
Property1:价值
Property2:价值
...
PropertyN:价值
(+/-)CustomClass.Object2
Property1:价值
Property2:价值
...
PropertyN:价值
如果我使用[ExpandableObject]
上ObservableCollection<>
只显示计数属性.
编辑:(添加代码)
MainWindow.xaml:
<Window x:Class="PropGridExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PropGridExample"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<xctk:PropertyGrid x:Name="PropertyGrid" SelectedObject="{Binding BindingItem}"></xctk:PropertyGrid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
MainWindowViewModel mwvm = new MainWindowViewModel();
this.DataContext = mwvm;
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
MainWindowViewModel.cs
public class MainWindowViewModel
{
public Item BindingItem { …
Run Code Online (Sandbox Code Playgroud) 我有一组具有一组属性的类如下所示.
class ContactInfo
{
[ReadOnly(true)]
[Category("Contact Info")]
public string Mobile { get; set; }
[Category("Contact Info")]
public string Name{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
此类的对象被分配给属性网格,以便用户可以更新现有联系人.你可以看到Mobile被标记为ReadOnly.
但是,当我想添加一个全新的联系人时,我希望用户能够编辑联系人移动设备.为此,我需要在将对象分配给属性网格之前从Type中动态删除Readonly属性.可能吗?
我知道我可以通过编写自定义类型描述符等来实现这一点,但是这个要求是多么简单; 我错过了一个简单的方法.
能够在BooleanConverter中设置"true"和"false"的字符串可能就是我所需要的,但是标准的BooleanConverter似乎不允许你设置自定义字符串.
我希望自动显示每个IList
在我的可扩展PropertyGrid
(通过"可扩展",我显然意味着将显示项目).我不想在每个列表上使用属性(再次,我希望它适用于每个列表IList
)
我试图通过使用自定义PropertyDescriptor
和a来实现它ExpandableObjectConverter
.它工作正常,但在我从列表中删除项目后,PropertyGrid
没有刷新,仍然显示已删除的项目.
我尝试使用ObservableCollection
同时提高OnComponentChanged
,也RefreshProperties
属性,但没有任何效果.
这是我的代码:
public class ExpandableCollectionPropertyDescriptor : PropertyDescriptor
{
private IList _collection;
private readonly int _index = -1;
internal event EventHandler RefreshRequired;
public ExpandableCollectionPropertyDescriptor(IList coll, int idx) : base(GetDisplayName(coll, idx), null)
{
_collection = coll
_index = idx;
}
public override bool SupportsChangeEvents
{
get { return true; }
}
private static string GetDisplayName(IList list, int index)
{
return "[" + …
Run Code Online (Sandbox Code Playgroud) 我正在创建.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?
非常感谢!
我正在PropertyGrid
通过实现自定义对象类型的显示方式ICustomTypeDescriptor
.我允许用户创建自己的自定义属性,这些属性存储在单个键和值字典中.我能够PropertyDescriptors
为这些值创建所有值并在属性网格中查看它们.但是,我还想显示所有默认属性,如果PropertyGrid
通过反射填充而不是覆盖ICustomTypeDescriptor.GetProperties
方法,则会显示这些属性.
现在我知道如何获取对象的类型,然后GetProperties()
,但这会返回一个PropertyInfo
not 数组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) 我想避免在我编写自定义UITypeEditor的某个类型的每个实例上放置EditorAttribute.
我不能在类型上放置EditorAttribute,因为我无法修改源代码.
我引用了将要使用的唯一PropertyGrid实例.
我是否可以告诉PropertyGrid实例(或所有实例)在遇到特定类型时使用自定义UITypeEditor?
这是一篇MSDN文章,它提供了如何在.NET 2.0或更高版本中执行此操作的起点.
我是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但是我没有看到任何属性定义.我觉得我必须遗漏一些基本的东西?我应该在代码隐藏中添加任何内容吗?
我有很多我正在使用的自定义类,我将解释并发布示例.在解释他们所做的一切之后,我将尝试清楚地描述我的错误发生的条件.
首先,我使用PropertyGrid来显示几种不同类型对象的属性.因为PropertyGrid的默认绑定不是我想要的描述,我创建了一些自定义类,我将其称为"显示"类.这些Display类是通过传入一个对象然后创建属性来构造的,这些属性返回格式良好的字符串以及传入的真实对象的公共属性(在某些情况下是方法)的描述.
我将用一些简短的示例代码演示这个:
以下是我想在PropertyGrid中显示的对象示例:
public class Joint
{
public Joint(...)
{...}
//properties
public string Name { get; set;}
public CustomObject CC { get; set;}
public List<CustomObject> Custom List { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
字符串属性"Name"在PropertyGrid中显示正常但是CustomObject和List没有以对用户友好的方式显示.
所以我尝试通过编写这个类来创建一个解决方案:
public class DisplayJoint
{
private Joint _jnt;
public DisplayJoint(Joint jnt)
{
_jnt = jnt;
}
//properties
public string Name { get { return _jnt.Name; } }
[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public DisplayCustomObject CC { get { return new DisplayCustomObject(_jnt.CC); } }
[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public List<CustomObject> CustomList { get; set;}
} …
Run Code Online (Sandbox Code Playgroud) 在下图中,"MyCars"是一个集合.如果对象的属性是集合,则在PropertyGrid中,如果选择了该项,则该值将显示为字符串"(Collection)",并带有右侧的按钮.
是否可以更改"(收集)"值?如果是这样,怎么样? 我问的原因是因为我已经为我的程序中的PropertyGrid中出现的对象实现了一个自定义UITypeEditor.到目前为止,右侧的按钮出现,但文本值与属性的显示名称相同.我想在那里出现一个不同的字符串.
编辑:对于什么是值得的,我知道我可以覆盖PaintValue
从UITypeEditor的方法,并提供一个图标,我最终可能会,如果我解决不了这个问题,这样做,但我还是想知道是否以及如何"(集合)"文本可以更改.
propertygrid ×10
c# ×8
.net ×5
winforms ×3
wpf ×2
controls ×1
propertyinfo ×1
reflection ×1
uitypeeditor ×1
xceed ×1