0

私は、propertyGrid のようなコントロールを意図したものを達成するのに行き詰まっていますが、私の場合、特定のプロパティの前に値があり、後に値があります。たとえば、プロパティが name の場合、2 つの値が name before と name after となります。

class Person
    {

        #region  class constructor
        /// <summary>
        /// class constructor
        /// </summary>
        /// <param name="_person"></param>
        public Person(string before,string after)
        {
            this.nameBefore = before; // assign beforename to namebefore
            this.nameAfter = after;  // assign aftername to nameAfter
        }

        #endregion class constructor

        #region properties

        /// <summary>
        /// Name property
        /// </summary>
        private string nameBefore;

        /// <summary>
        /// public Property
        /// for nameBefore
        /// </summary>
        public string NameBefore
        {
            get { return nameBefore; }
            set { nameBefore = value; }
        }


        /// <summary>
        /// name property after
        /// </summary>
        private string nameAfter;


        /// <summary>
        /// public property for nameAfter
        /// </summary>
        public string NameAfter
        {
            get { return nameAfter; }
            set { nameAfter = value; }
        }

        #endregion properties

    }

このクラスのすべてのプロパティを公開する必要があります。これらのプロパティは、値の前後に値を持つ可能性があります。これらの値は外部で設定されます。プロパティ グリッドと同じように、これらの値を入力する必要があります。しかし、私の場合、もう1つの追加の列があります(後の値)。

それは私のxamlがどのように見えるかです:

<Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition  Height="20" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <TextBlock Background="Gray" Padding="5,2,5,5" Grid.Column="0" Grid.Row="0" Text="Property" />
        <TextBlock Background="Gray" Padding="5,2,5,5" Grid.Column="1" Grid.Row="0"  Text="Before" />
        <TextBlock Background="Gray" Padding="5,2,5,5" Grid.Column="2" Grid.Row="0" Text="After" />

        <TextBlock Grid.Column="0" Grid.Row="1" Text="Name" />
        <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Before }" />
        <TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding After }" />

    </Grid>

私はこのようなものが必要です

プロパティ ウィンドウ

プロパティ ウィンドウ

このようなものをプログラムで取得できますか? プロパティとその複数の値を持つことを意味します。multikeyvalue 辞書にすることもできますか?

4

1 に答える 1

1

すべてのプロパティを複製すると、多くの時間を無駄にします。そうする代わりに、プロパティを含むクラスを複製するだけです。このようにして、次のようなことができます。

の各行のクラスを定義しGridます (表示用):

public class PropertyGridRow : INotifyPropertyChanged
{
    public string PropertyName { get; set; }
    public object PropertyValueBefore { get; set; }
    public object PropertyValueAfter { get; set; }
}

次に、次のように入力するか、ループで少し異なる方法で入力できます。

Person before = GetBeforePerson();
Person after = GetAfterPerson();
...
PropertyGridRow propertyGridRow = new PropertyGridRow();
propertyGridRow.PropertyName = "Some Property";
propertyGridRow.PropertyValueBefore = before.SomeProperty;
propertyGridRow.PropertyValueAfter = after.SomeProperty;
PropertyGridRows.Add(propertyGridRow);

次に、次のように表示します。

<GridView ItemsSource="{Binding PropertyGridRows}" ... />
于 2013-11-13T13:57:24.560 に答える