This is a migrated thread and some comments may be shown as answers.

ShowDialog in MVVM

2 Answers 87 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Efrael
Top achievements
Rank 1
Efrael asked on 07 May 2011, 04:46 PM
Hi,

I'd like to handle the ShowDialog event in the viewmodel.
What I exactly like to do is to set a default Subject for the Add new appt. dialog window.

Using the mvvmlight pattern, I setup a command in the viewmodel

Private _addingAppointment As ICommand
Public ReadOnly Property AddingAppointmentCommand() As ICommand
    Get
        If _addingAppointment Is Nothing Then
            _addingAppointment = New RelayCommand(Of Object)(AddressOf CommandExecute, AddressOf CanCommandExecute)
        End If
        Return _addingAppointment
    End Get
End Property
Private Sub CommandExecute(parameter As Object)
    ' Code here
End Sub
Private Function CanCommandExecute(parameter As Object) As Boolean
    ' Code here
    Return True
End Function


This is the XAML i tryed to use inside the ScheduleView section (using interaction)

 
<i:Interaction.Triggers>
    <i:EventTrigger EventName="ShowDialog">
        <i:InvokeCommandAction Command="{Binding ViewModel.AddingAppointmentCommand, Source={StaticResource Container}, Mode=OneWay}"
                          CommandParameter="{Binding ShowDialog.ShowDialogEventArgs.DialogViewModel, ElementName=ScheduleView}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

 

 


I binded the ShowDialog as command parameter, but of course that's wrong, and is not a Property but an Event.

So, how can I make it work? And after how can I set up a custom default subject binded to another control's property (this property is available on the viewmodel yet)

Thanks

2 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 11 May 2011, 06:01 PM
Hi Raffele,

Thank you for contacting us.

Could you please specify do you use a custom appointment? If you do, you could set a default Subject in the custom appointment constructor.

If this doesn't help, you could handle the AppointmentCreating event and set Subject for the your appointment using the AppointmentCreatingEventArgs.Appointment.Subject property. If you use the MVVM Light V3 or above, you could use the EventToCommand behavior to bind the AppointmentCreating event to a ICommand property. Please, refer to the following link where you can find additional information - http://geekswithblogs.net/lbugnion/archive/2010/03/16/whatrsquos-new-in-mvvm-light-v3.aspx

I hope this helps.

All the best,
George
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Efrael
Top achievements
Rank 1
answered on 11 May 2011, 07:26 PM
Thank you George for your answer.
I'm not going to work on this for one week 'cause I'm travelling, but it sounds good to try with the AppointmentCreatingEventArgs.
I'll work on it next week and let you know.

Thanks
Tags
ScheduleView
Asked by
Efrael
Top achievements
Rank 1
Answers by
George
Telerik team
Efrael
Top achievements
Rank 1
Share this question
or