Pergunta

I need to implement selection change event for list and combo boxes in a WinRT application. I am using MvvmCross but AFAIK this is a WinRT rather than Mvx-specific issue. System.Windows.Interactivity is not available for WinRT applications so I can't use technique based on i:Interaction.Triggers. I would like to implement binding in a true MVVM way without switching to code-behind, so I can reuse as much as possible on other platforms. What is the reasonable approach to implement it in WinRT app? I haven't found any examples in MvvmCross samples.

Thanks in advance

Foi útil?

Solução 2

I think this is a general issue with Mvvm on WinRT

For some unknown reason, Microsoft didn't include Behaviors in WinRT. (There are theories like the fact they ran out of time, they didn't want to because of Expression Blend changes, etc...)

There have been quite a few blog posts and articles about how to work around this - most of it centered around Joost van Schaik's excellent library:

I've not done this myself - I tend not to use SelectionChanged but instead to put ICommands within each ListItem instead. If you get Joost's library working I'd love to see a sample :)

Outras dicas

If you are looking for behaviors in WinRT with MvvmCross, you can now use the Windows.UI.Interactivity nuget package for it (https://nuget.org/packages/Windows.UI.Interactivity).

When using it with MvvmCross, I made a copy with some small alterations to the existing MvxEventToCommand class (inherit from TriggerAction(FrameworkElement) instead of TriggerAction(DependencyObject)). Works like a charm.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top