-5

我正在为以下屏幕使用 poco 类,但我只是想知道如何实现此屏幕的上下移动元素在此处输入图像描述

我正在使用 ObservableCollection 将我的项目添加到相互列表中,我的问题是如何实现上移和下移。我不,我需要实时更改 poco 类,但不确定我将如何实现这一点

   private void AddColumn(object sender, RoutedEventArgs e)
    {

        if (this.WizardData == null)
            return;

        if (this.WizardData.ConcreteCustomColumnsProxy == null)
            this.WizardData.ConcreteCustomColumnsProxy = new ObservableCollection<CustomColumnsModel>();

        this.WizardData.ConcreteCustomColumnsProxy.Add(new CustomColumnsModel() { CustomColumnsDisplayName = txtDsiplayName.Text
            , CustomColumnsOrder = 1, CustomColumnsWidth = Convert.ToInt32(txtWdith.Text) });

        this.listView1.ItemsSource = this.WizardData.ConcreteCustomColumnsProxy;
        this.listView1.UnselectAll();

        this.listView1.Items.Refresh();

我的 Poco 课程如下

 public event PropertyChangedEventHandler PropertyChanged;
    public const string IdPropertyName = "CustomColumnsID";
    private Guid _Id = Guid.Empty;
    public Guid CustomColumnsID
    {
        get { return _Id; }
        set
        {
            if (_Id == value)
                return;
            _Id = value;
            NotifyPropertyChanged(IdPropertyName);
        }
    }


    public string CustomColumnsDisplayName { get; set; }
    public int CustomColumnsWidth { get; set; }
    public int CustomColumnsOrder { get; set; }  


    protected void NotifyPropertyChanged(string key)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(key));
        }
    }

    public EnterpriseManagementObject ActualData { get; private set; }

}
4

1 回答 1

4

你有某种DataGrid控制权。您需要将集合属性数据绑定到该DataGrid.ItemsSource属性,并将与集合中的项目相同类型的属性绑定到该DataGrid.SelectedItems属性:

<DataGrid ItemsSource="{Binding YourCollectionProperty}" 
    SelectedItem="{Binding YourItemProperty}" />

DataGrid.SelectedItems属性数据绑定到您的YourItemProperty后,您可以通过设置此属性来设置在 UI 中选择哪个项目。因此,要将所选项目向下移动一个位置,您可以执行以下操作:

int selectedIndex = YourCollectionProperty.IndexOf(YourItemProperty);
if (YourCollectionProperty.Count > selectedIndex) 
    YourItemProperty = YourCollectionProperty.ElementAt(selectedIndex + 1);

这就是您执行“向下移动”Button和“向上移动”操作的Button方式将类似地工作。然后你需要做的就是连接一些ClickICommand事件处理程序。

于 2014-09-03T09:28:56.230 回答