我在C#中找不到PropertyGrid的任何可用属性列表,你知道我在哪里可以找到它吗?
谢谢.
我想使用propertygrid编辑键值(字符串,字符串)项的列表.当我使用Dictionary<string,string>
as类型时,propertygrid将显示一个GUI,但它似乎没有"启用",即.我无法添加任何物品.
是否支持Dictionary对象,或者是否有任何其他对象可以解决此问题?
好吧所以我在C#方面的术语并不是很好,所以我将尝试用一个小例子来解释这个.如果您创建了一个在PropertyGrid中使用的类,并且您具有以下值:
class Test
{
public Point example { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这将生成一个PropertyGrid,它具有一个可扩展的对象"example",它具有字段X和Y,以便创建一个"Point".
我正在尝试创建一个对象"name",其中包含"firstname"和"lastname"字段,所以我有:
class Test
{
public Name example { get; set; }
}
public struct Name
{
public string firstname { get; set; }
public string lastname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然而,这并不按预期工作.
我认为我需要覆盖一些方法才能使其正常工作,但是由于我没有真正使用PropertyGrids的术语,因此我很难找到解决方案.
任何帮助都会很棒.
我有一个带有字符串属性的类,同时具有getter和setter,它通常很长,以至于PropertyGrid会截断字符串值.如何强制PropertyGrid显示省略号,然后启动包含多行文本框的对话框以便于编辑属性?我知道我可能要在属性上设置某种属性,但属性和方法是什么?我的对话框是否必须实现一些特殊的设计器界面?
更新: 这可能是我的问题的答案,但我无法通过搜索找到它.我的问题更为通用,其答案可用于构建任何类型的自定义编辑器.
目前,我有一个类型为A的对象,正由PropertyGrid查看.但是,它的一个属性是B类.B类属性是不可扩展的.我怎样才能改变这一点:
a)我可以展开自定义对象属性b)这些更改绑定到该属性
这是我到目前为止的代码:
using System;
using System.Windows.Forms;
using System.ComponentModel;
namespace PropGridTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
A a = new A
{
Foo = "WOO HOO!",
Bar = 10,
BooFar = new B
{
FooBar = "HOO WOO!",
BarFoo = 100
}
};
propertyGrid1.SelectedObject = a;
}
}
public class A
{
public string Foo { get; set; }
public int Bar { get; set; …
Run Code Online (Sandbox Code Playgroud) 我有一个Winform应用程序,它使用颜色突出显示某些事物.我想让用户改变'他们'的颜色.作为练习,我想我会创建一个类的实例,其中包含颜色的属性,并将其分配给属性网格(以获得一个漂亮的编辑器).
这似乎工作正常,但我想我想让用户重置颜色(在他们摆弄并将它们设置为20个米色)之后.所以,我在表单中添加了一个"重置"按钮,它将我的对象的颜色属性设置回默认值.
但是,它似乎在设置我的对象属性时,属性网格不会改变.如果在重置后,我执行属性网格"刷新",它具有重置颜色.
我假设属性网格不知道底层对象已被更改?
在这种情况下是否缺少某些东西,或者我应该接受它并在重置对象时调用Refresh方法?
谢谢
(这里非常相似的问题)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.propertyGrid1.SelectedObject = new Colours();
}
private void button1_Click(object sender, EventArgs e)
{
Colours colours = this.propertyGrid1.SelectedObject as Colours;
colours.Reset();
}
}
public partial class Colours : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public Color ColourP1 { get; set; }
public void Reset()
{
this.ColourP1 = Color.Red;
var handler = this.PropertyChanged;
if (handler != null) handler(this, new …
Run Code Online (Sandbox Code Playgroud) c# data-binding propertygrid inotifypropertychanged winforms
我想为对象的属性添加一些自定义的以PropertyGrid为中心的属性,以提供更丰富的编辑,隐藏一些值并将它们分类,因为我正在使用的那个类不提供这样的功能而且我什么也做不了关于它.
真的,这是MS的应用程序设置生成代码,所以你不能以任何方式扩展它的属性.请参阅我的另一个问题:运行时AppSettings.settings编辑器对话框
我在我的应用程序中使用属性网格来显示对象属性的名称和值.
默认情况下,列的宽度(名称和属性)的比例为50:50.我们可以选择滑动分离器来改变这个宽度.我想知道如何以编程方式调整此宽度,以便可以设置为25:75.
如何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) 正如标题所说,我注意到当类"T"的所有属性都是只读时,类别不会显示在集合(Of T)的**PropertyGrid*(在其默认集合编辑器中)中.
下面的代码代表了我的代码结构:
C#:
[TypeConverter(typeof(ExpandableObjectConverter))]
public class TestClass1 {
public TestClass2 TestProperty1 {get;} = new TestClass2();
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public sealed class TestClass2 {
[TypeConverter(typeof(CollectionConverter))]
public ReadOnlyCollection<TestClass3> TestProperty2 {
get {
List<TestClass3> collection = new List<TestClass3>();
for (int i = 0; i <= 10; i++) {
collection.Add(new TestClass3());
}
return collection.AsReadOnly();
}
}
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public sealed class TestClass3 {
[Category("Category 1")]
public string TestProperty3 {get;} = "Test";
}
Run Code Online (Sandbox Code Playgroud)
VB.NET:
<TypeConverter(GetType(ExpandableObjectConverter))>
Public Class TestClass1
Public ReadOnly Property TestProperty1 As TestClass2 = …
Run Code Online (Sandbox Code Playgroud) propertygrid ×10
c# ×9
.net ×4
winforms ×3
data-binding ×2
attributes ×1
expand ×1
generics ×1
vb.net ×1
view ×1
wpf ×1