I have a user control defined in my project which contains a control to which I need a reference in my view model. To that end I am handling the loaded event of the user control in my xaml like so:
<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>
I have used exactly the same sort of CommandParameter binding in other parts of the project and it has worked well, but for some reason the scheduler object to which I require the reference is not getting passed to the command shown below.
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
A breakpoint placed in the SchedulerLoaded sub shows that the value of the parameter obj is Nothing.
Is it possible that there simply is a tangible version of the scheduler control that I can reference at the time of the Loaded event or is the use of elementName incorrect here.
I'd welcome any thoughts that you might have.