【发布时间】:2021-06-30 11:01:16
【问题描述】:
我想在 UserControl 使用 MVVM 更改为另一个时实现一些功能。到目前为止,我已经尝试过:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<i:InvokeCommandAction Command="{Binding ClosingCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
视图模型:
private ICommand _closingCommand;
public ICommand ClosingCommand
{
get
{
_closingCommand = new RelayCommand(new Action<object>(OnClosingCommand));
return _closingCommand;
}
set { SetProperty(ref _closingCommand, value); }
}
private void OnClosingCommand(object parameter)
{
//My functions here
}
它适用于LoadedCommand,但不适用于Closing 命令。
【问题讨论】:
-
这里有任何答案吗:stackoverflow.com/questions/502761/disposing-wpf-user-controls 帮助?在很多情况下关闭不会触发,我猜你想在该命令中执行一些最终操作
标签: c# wpf xaml mvvm eventtrigger