MVVM将EventArgs作为命令参数传递

我正在使用Microsoft Expression Blend 4 

我有一个浏览器..,


[XAML] ConnectionView“后面的空代码”


        <WebBrowser local:AttachedProperties.BrowserSource="{Binding Source}">

            <i:Interaction.Triggers>

                <i:EventTrigger>

                    <i:InvokeCommandAction Command="{Binding LoadedEvent}"/>

                </i:EventTrigger>

                <i:EventTrigger EventName="Navigated">

                    <i:InvokeCommandAction Command="{Binding NavigatedEvent}" CommandParameter="??????"/>

                </i:EventTrigger>

            </i:Interaction.Triggers>

        </WebBrowser>  

[C#] AttachedProperties类


public static class AttachedProperties

    {

        public static readonly DependencyProperty BrowserSourceProperty = DependencyProperty . RegisterAttached ( "BrowserSource" , typeof ( string ) , typeof ( AttachedProperties ) , new UIPropertyMetadata ( null , BrowserSourcePropertyChanged ) );


        public static string GetBrowserSource ( DependencyObject _DependencyObject )

        {

            return ( string ) _DependencyObject . GetValue ( BrowserSourceProperty );

        }


        public static void SetBrowserSource ( DependencyObject _DependencyObject , string Value )

        {

            _DependencyObject . SetValue ( BrowserSourceProperty , Value );

        }


        public static void BrowserSourcePropertyChanged ( DependencyObject _DependencyObject , DependencyPropertyChangedEventArgs _DependencyPropertyChangedEventArgs )

        {

            WebBrowser _WebBrowser = _DependencyObject as WebBrowser;

            if ( _WebBrowser != null )

            {

                string URL = _DependencyPropertyChangedEventArgs . NewValue as string;

                _WebBrowser . Source = URL != null ? new Uri ( URL ) : null;

            }

        }

    }

最后:

使用命令绑定工作正常,并显示MessageBoxes


我的问题:

如何在导航事件发生时将NavigationEventArgs作为命令参数传递?


largeQ
浏览 1072回答 3
3回答

鸿蒙传说

它不容易支持。这是一篇文章,内容涉及如何将EventArgs作为命令参数传递。您可能希望研究使用MVVMLight - 它直接支持命令中的EventArgs; 你的情况看起来像这样:&nbsp;<i:Interaction.Triggers>&nbsp; &nbsp; <i:EventTrigger EventName="Navigated">&nbsp; &nbsp; &nbsp; &nbsp; <cmd:EventToCommand Command="{Binding NavigatedEvent}"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PassEventArgsToCommand="True" />&nbsp; &nbsp; </i:EventTrigger>&nbsp;</i:Interaction.Triggers>
打开App,查看更多内容
随时随地看视频慕课网APP