Hello!
I have a problem with new Prism 6.3 which was released recently. I'm trying to use new feature of Prism 6.3 so EventToCommandBehavior
. It works on Android but on iOS I have exception:
EventToCommandBehavior not found in xmlns clr-namespace:Prism.Behaviors
which is weird, because the same namespace is found by Android. So the error message is probably totally misleading.
Anyway the code is super simple. I also have entire project (with packages and everything) on github, here:
github.com/LouisaBickley/PrismDemo
**If you don't know how to solve it, can you just get the code from repo and try to run it? also if you could add info about your config, like mac version..
**
View:
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms" x:Class="PrismDemo.StartPage"> <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" /> <ListView ItemsSource="{Binding People}"> <ListView.Behaviors> <b:EventToCommandBehavior Command="{Binding PersonSelectedCommand}" EventName="ItemTapped" EventArgsParameterPath="Item" /> </ListView.Behaviors> </ListView> </ContentPage>
ViewModel:
using Prism.Commands; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PrismDemo { public class StartPageViewModel : BindableBase { public ObservableCollection<string> People { get; set; } public StartPageViewModel() { People = new ObservableCollection<string>(); People.Add("John"); People.Add("Tom"); People.Add("Kate"); People.Add("Mike"); } public DelegateCommand<string> PersonSelectedCommand => new DelegateCommand<string>(OnPersonSelectedCommandExecuted); void OnPersonSelectedCommandExecuted(string name) { Debug.WriteLine("Hi " + name + "!"); } } }
That's IT!
The exception is while starting the app (again, it's on iOS only)
You app wasn't bootstrapped correctly so I'm guessing the iOS libraries weren't inititalized.
I've fixed up your sample app and EventToCommand works fine now in iOS (well tested in a simulator).
Check out the changes with the addition of App.xaml, Adding Unity and changes to the platform specific projects.
Hope this helps.
Answers
@Louisa
You app wasn't bootstrapped correctly so I'm guessing the iOS libraries weren't inititalized.
I've fixed up your sample app and EventToCommand works fine now in iOS (well tested in a simulator).
Check out the changes with the addition of App.xaml, Adding Unity and changes to the platform specific projects.
Hope this helps.
@NMackay Thanks! I will have a chance to test it in a few hours! Will let you know how it went
BTW. Wait, I don't get it.. Unity? The game engine? Do you know if the solution would be the same if I want to use CocosSharp for example? Do I still need to add Unity?
@Louisa
No, it's Unity the IoC container, not the games engine
https://msdn.microsoft.com/en-gb/library/ff649564.aspx
Prism is designed round the principles of dependency injection so it's better to down that route with Prism, you'll need it for example to inject the navigation service into your viewmodels. Using Unity won't stop you using CocosSharp in your app.
Let me know you you get on.
@NMackay your project works great! Thanks! I will probably use IoC after all...
But it's still bugging me.. if it's possible to do it without IoC container. When someone has just one view and viewmodel.