【发布时间】:2015-02-24 21:35:09
【问题描述】:
我正在使用MVVM棱镜,我的代码如下
<ListBox x:Name="myListBox" Grid.Row="0"
ItemsSource="{Binding Path=_mySOurce}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectionChanged="myListBox_SelectionChanged">
</ListBox>
<Button Grid.Row="1" x:Name="btnSelect"
Command="{Binding Path=SaveCommand}" Content="Select" Margin="396,0,10,0"></Button>
在我的代码中我有
public ICommand SaveCommand { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
this.SaveCommand = new DelegateCommand<object>(this.OnSaveClick, this.CanSaveExecute);
}
private void myListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void OnSaveClick(object arg)
{
MessageBox.Show("Performed Click");
}
private bool CanSaveExecute(object arg)
{
if (myListBox.SelectedIndex > 0)
return true;
else return false;
}
我无法在选择更改事件中触发它。
我错过了什么?
【问题讨论】:
-
在 myListBox_SelectionChanged 中触发 SaveCommand.Execute(parameter) ?
-
如果您想在 SelectionChanged 处触发该命令,那么该事件的处理程序在哪里?