Unable to work with ViewModel property in monodroid #41

Closed
Alphapage opened this Issue Oct 23, 2012 · 11 comments

Comments

Projects
None yet
2 participants
Contributor

Alphapage commented Oct 23, 2012

Hello,
I added this line to OnViewModel method in CustomerListView.cs (monodroid CustomerManagement project):
System.Diagnostics.Debug.WriteLine("find customer:" + ViewModel.Customers.First(c => c.ID == "1").Name);

The project doesn't compile because it needs System.Windows.dll assembly reference.
Do I have to change to IList instead of IObservableCollection ? Is it a limitation ?

Thanks in advance.

Contributor

slodge commented Oct 23, 2012

There is a System.Windows.dll for Droid included - try adding it as a reference.

See https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/System.Windows - it's just a shim that does some type redirection

For more on type redirection, see the answer in http://stackoverflow.com/questions/10361457/is-it-possible-to-use-a-portable-class-library-that-references-system-net-in-mon

// ---

Minor: The one place where you might still hit problems (where I hit problems) is if you try to access an ICommand in non-portable code - you hit a weird link error :/ Not worked this out yet - which is why you might find some View codebehind which uses ViewModel methods rather than ViewModel Commands

Contributor

slodge commented Oct 23, 2012

PS In case you were wondering, the reason this is needed is all Microsoft's fault - they bundled all the functionality from System.Windows, System.Net, etc inside the single Silverlight System.dll - and it's caused chaos ever since :)

Contributor

Alphapage commented Oct 23, 2012

I already added System.Windows.Droid.dll to the project without success.
I always get this error:
The type 'System.Collections.Specialized.INotifyCollectionChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
I check and 'System.Collections.Specialized.INotifyCollectionChanged' is forwarded in System.Windows.Droid.dll assembly.

Contributor

slodge commented Oct 23, 2012

In that case you're hitting the same sort of PCL issues as I've seen with ICommand

It's to do with the Compiler and strong type checking I think.

I'll try the PCL team to see if they can help.

I would also try Xamarin, but I've already got a few PCL issues in with them - and I think I may be close to the level where the questions will upset them :/

Treading carefully....

Contributor

slodge commented Oct 23, 2012

As workarounds:

  • can you use IList instead?
  • can you try creating a separate MonoDroid library project and try referencing the INotifyCollectionChanged from there? (it sounds wrong, but I have a feeling this problem only occurs in UI projects?!)
  • can you move the functionality inside the Core PCL?
  • sit tight and hope for PCL and/or Xamarin to come back with a solution?
Contributor

Alphapage commented Oct 23, 2012

My workaround is to use DataStore.GetCustomer as you suggested:
System.Diagnostics.Debug.WriteLine("find customer:" + ViewModel.DataStore.GetCustomer("1").Name);
I use the functionality inside the Core PCL.
I don't know if this issue can be closed because you seem to get a way to solve the problem regarding your previous comment. I will try to test the command line batch if I have time.

Contributor

slodge commented Oct 28, 2012

Got nowhere with StackOverflow or with Xamarin forums.

Have pinged Xamarin on this - https://bugzilla.xamarin.com/show_bug.cgi?id=8035

Contributor

slodge commented Nov 22, 2012

This is solved! Solved! Solved!

:)

Follow @dsplaisted now - and tell him THANKS!

:)

@slodge slodge closed this Nov 22, 2012

Contributor

Alphapage commented Nov 24, 2012

I test quickly and I was able to run my linq query. You got it finally. Congratulations. @dsplaisted :+1

martijn00 pushed a commit to martijn00/MvvmCross that referenced this issue Dec 8, 2016

martijn00 pushed a commit to martijn00/MvvmCross that referenced this issue Apr 13, 2017

Merge pull request #41 from MarcBruins/master
Add Lato font and fix padding top issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment