Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 为什么参数不能通过继电器命令传递_Wpf_Vb.net_Relaycommand - Fatal编程技术网

Wpf 为什么参数不能通过继电器命令传递

Wpf 为什么参数不能通过继电器命令传递,wpf,vb.net,relaycommand,Wpf,Vb.net,Relaycommand,我在项目中定义了一个用户控件,该控件包含一个我需要在视图模型中引用的控件。为此,我在xaml中处理用户控件的已加载事件,如下所示: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://sch

我在项目中定义了一个用户控件,该控件包含一个我需要在视图模型中引用的控件。为此,我在xaml中处理用户控件的已加载事件,如下所示:

<UserControl
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" 
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         x:Class="SchedulerView" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Unloaded">
        <i:InvokeCommandAction Command="{Binding Path=SchedulerUnloadedCommand}" />
    </i:EventTrigger>
    <i:EventTrigger EventName="Loaded">
        <i:InvokeCommandAction Command="{Binding Path=SchedulerLoadedCommand}" CommandParameter="{Binding ElementName=scheduler}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>
SchedulerLoaded子文件中的断点显示参数obj的值为Nothing

是否有可能在加载事件时我可以引用调度程序控件的一个具体版本,或者这里使用的elementName不正确


我欢迎您的任何想法。

您是否在输出窗口中看到任何绑定错误?您确定调度程序元素的DataContext是您想要的对象吗?我可能错了,但我认为您所指向的元素在调用命令时可能没有数据绑定,因为您正在使用UserControl的Loaded事件。@vesan感谢您的想法。输出窗口没有绑定错误,因此我认为可以排除该方面。理论上,数据上下文是在实例化时设置的,但我确实接受您的观点,即我所关注的元素在加载事件时可能尚未绑定。整个wpf绑定对我来说还是比较新的,所以我不确定如何积极地验证它。回到绘图板上,我想。维桑的建议+1。XAML对于声明控件的顺序以及如何绑定控件非常挑剔。您是否可以将CommandBinding转换为调度程序的Loaded事件,而不是UserControl的Loaded事件?@vesan您是完全正确的,因为在触发用户控件“Loaded”事件时,调度程序没有正确加载/绑定。不知何故,我错过了调度程序控件本身的已加载事件,但谢天谢地,当连接到该事件时,它按预期工作。谢谢你给我指明了正确的方向。你的时间加1。
Private _schedulerLoadedCommand As ICommand

Public ReadOnly Property SchedulerLoadedCommand As ICommand
    Get
        If _schedulerLoadedCommand Is Nothing Then
            Dim MySchedulerLoaded As New Action(Of Object)(AddressOf SchedulerLoaded)
            _schedulerLoadedCommand = New RelayCommand(MySchedulerLoaded)
        End If
        Return _schedulerLoadedCommand
    End Get
End Property

Private Sub SchedulerLoaded(ByVal obj As Object)
    mrvm.scheduler = DirectCast(obj,C1Scheduler)

End Sub