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

标签 wpf mvvm caliburn

我已经按照 example 构建了一个 UI ...并想添加两个按钮来重新排序“那里”列表中的列表框选定项目(上移 - 下移)。关于使用 Caliburn Micro 执行此操作的任何想法?

最佳答案

您需要为 SelectedThereItem 添加属性并将其绑定(bind)到 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"/>

View 模型:
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
}

关于wpf - Caliburn Micro Listbox 向上或向下移动项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28869749/

相关文章:

c# - 如何播放声音文件?

c# - WPF MVVM 导航技术

android - 如何从 ViewModel 正确传递事件?

c# - 当 UserControl 具有 DataContext 时,UserControl 的 DependencyProperty 为 null

mvvm - 使用匿名对象 (MVVMCross) 在 WP7 上将变量从 ViewModel 传递到 ViewModel 时出现 methodAccessException

c# - 使用 caliburn micro 和 autofac 填充初始 View 模型数据

wpf - Caliburn:如何将托管控件绑定(bind)到 ViewModel 属性

c# - WPF网页浏览器控件中的OL3-Cesium

wpf - 在 WPF 中为字符串资源添加回车

WPF DataGrid 绑定(bind)不起作用 Caliburn Micro