控制添加键/值对?

mpe*_*pen 1 wpf wpf-controls

我需要一个控件来允许用户添加/删除/编辑键/值对的行.什么是最好的控制用于此?有人有例子吗?我对WPF很新.

H.B*_*.B. 5

我将使用带有两个带标签的文本框的简单对话,新对将添加到原始数据中,应绑定到原始数​​据,DataGrid以便自动生成行.

编辑:DataGrid示例解决方案.
XAML:

<Window
    ...
    DataContext="{Binding RelativeSource={RelativeSource Mode=Self}}">
    <StackPanel Orientation="Vertical">
        <DataGrid ItemsSource="{Binding GridData}"/>
    </StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

代码背后:
在窗口类中:

    private ObservableCollection<Pair> gridData = new ObservableCollection<Pair>(new Pair[]{new Pair()});
    public ObservableCollection<Pair> GridData
    {
        get { return gridData; }
    }
Run Code Online (Sandbox Code Playgroud)

配对类:

public class Pair : INotifyPropertyChanged
{
    private string key = "Key";
    public string Key
    {
        get { return key; }
        set
        {
            if (this.key != value)
            {
                key = value;
                NotifyPropertyChanged("Key");
            }
        }
    }


    private double value = 0;
    public double Value
    {
        get { return value; }
        set
        {
            if (this.value != value)
            {
                this.value = value;
                NotifyPropertyChanged("Value");
            }
        }
    }

    public Pair() { }
    public Pair(string key, double value)
        : this()
    {
        Key = key;
        Value = value;
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }

    #endregion
}
Run Code Online (Sandbox Code Playgroud)

您应该能够添加具有正常DataGrid功能的新对.