|
|
Hi there,
I'm just starting out with Prism, MVVM and would like some help putting the code below into a MVVM viewmodel
I tried EventHandler and DelegateCommand but cant get anything to work, I pasted the code I had
Public Sub PivotCommand(sender As Object, e As PivotViewerCommandsRequestedEventArgs) e.Commands.Add(New PivotViewerUICommand(CType(e.Item, Integer)))
End Sub
and binding with
CommandsRequested="{Binding Path=GetPivotCommand}" Private m_Piv As EventHandler(Of PivotViewerCommandsRequestedEventArgs)
Public Sub New()
m_Piv = New EventHandler(Of PivotViewerCommandsRequestedEventArgs)(AddressOf PivotCommand)
end sub
Public Sub PivotCommand(sender As Object, e As PivotViewerCommandsRequestedEventArgs)
e.Commands.Add(New PivotViewerUICommand(CType(e.Item, Integer)))
End Sub
Public Property GetPivotCommand As EventHandler(Of PivotViewerCommandsRequestedEventArgs)
Get
Return m_Piv
End Get
Set(value As EventHandler(Of PivotViewerCommandsRequestedEventArgs))
m_Piv = value
End Set
End Property
Thanks pqsik
|
|
Developer
Apr 24, 2012 at 7:25 PM
|
Hi,
If I am not mistaken you are trying to use a PivotViewerDefaultItemAdorner
in you view and you want to handle the CommandsRequested
event in your view model. Based on my understanding, it is not possible to define an event handler in the view model and create a binding to it from the view. As far as I know, you can only use bindings on
DependencyProperties and the CommandsRequested
is an event, not a property.
You can find more information about data bindings in the following article on
MSDN:
A possible approach could be to use a "event to command" behavior (like the
InvokeCommandAction provided in Expression Blend and
Prism) that could handle the CommandsRequested
event and invoke a command in the view model. However, it seems that you require to use the
PivotViewerCommandsRequestedEventArgs arguments provided by the event, which cannot be passed to the
command using the aforementioned behaviors as out of the box. Therefore, you might need to define your own "event to command" behavior for this scenario.
As a quick workaround, you might be able to wire this event and the view model's event handler manually in the view's code behind; however, take into account that this might not be a recommended practice when following the
MVVM pattern.
Also, as this is not strictly related to Prism, but to the
PivotViewer control, I believe you might find better support about this in the
PivotViewer's Silverlight forums:
Regards,
Damian Cherubini
http://blogs.southworks.net/dcherubini
|
|
|
|
Sorry for the delay in replying.
I maybe able to have a prism command for a button in the ItemAdorner. looking into that
Thanks
|
|