【发布时间】:2020-05-28 17:36:01
【问题描述】:
我想在我的 ViewModel 的 DelegateCommand 中包含“发送者”对象。
<WebBrowser>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Navigated">
<prism:InvokeCommandAction
Command="{Binding NavigatedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</WebBrowser>
private DelegateCommand<NavigationEventArgs> _onNavigated;
public DelegateCommand<NavigationEventArgs> NavigatedCommand => _onNavigated ?? (_onNavigated = new DelegateCommand<NavigationEventArgs>(OnNavigated, (e) => true));
private void OnNavigated(NavigationEventArgs e)
{
//TODO add code to access the WebBrowser.Document property
}
这不起作用:
private DelegateCommand<WebBrowser, NavigationEventArgs> _onNavigated;
什么是委托命令?
【问题讨论】:
-
您确定要命令吗?如果您需要控件,您可以使用 ui-stuff,因此只需将其放在代码隐藏中(事件获取发送者)。
-
@Haukinger PRISM MVVM。不是旧的代码隐藏。
-
你的命令是做什么的?它需要
sender做什么?代码隐藏非常适合做与视图相关的事情。 -
访问 WebBrowser 控件对象会暴露 Document 属性。
-
是什么阻止您将
Document放入CommandParameter?