Caliburn Micro Listbox 向上或向下移动项目

Caliburn Micro Listbox move item up or down

我在 example 之后构建了一个 UI... 并想添加两个按钮来重新排序 [=] 中的列表框选定项目(上移 - 下移) 13=] 列表。关于使用 Caliburn Micro 执行此操作的任何想法?

您需要为SelectedThereItem添加一个属性并绑定到ThereList:

XAML:

<ListBox x:Name="ThereList" SelectedItem="{Binding ThereSelectedItem}" ... />
<!-- Add buttons for ThereMoveUp and ThereMoveDown - use Caliburn naming convention -->
<Button x:Name="ThereMoveUp"/>
<Button x:Name="ThereMoveDown"/>

视图模型:

private Person _thereSelectedItem;
public Person ThereSelectedItem
{
    get { return _thereSelectedItem; }
    set
    {
        _thereSelectedItem = value;
        NotifyOfPropertyChange(() => ThereSelectedItem);
        NotifyOfPropertyChange(() => CanThereMoveDown);
        NotifyOfPropertyChange(() => CanThereMoveUp); 
    }
}

// Add event method handlers for ThereMoveUp/Down
public bool CanThereMoveUp { get { return _thereSelectedItem != null; } }
public void ThereMoveUp
{
    // Logic to move up
}

public bool CanThereMoveDown { get { return _thereSelectedItem != null; } }
public void ThereMoveDown
{
    // Logic to move down
}