0

I'm fairly new to development using Xamarin and MvvmCross, and am trying to port one of my windows apps to Android. It's a sliding puzzle game for children.

I was hoping I would be able use a list of Tiles as the ItemsSource for an MvxGridView. Each Tile object would have a Row and Column property to determine which "cell" (row/column) it would be placed in. Then, when the user taps a tile, I would be able to check if that tile is next to an empty space and, if so, change the corresponding Tile object's Row and Column properties. Because of the binding, the tile would then automatically be placed in the right "cell" in the grid, preferably using a nice sliding animation. I would like to use this type of solution because I would be able to put all the logic in viewmodel and model classes, instead of in the view. And it would be similar to the solution I used in my Windows store app, which would allow me to reuse a lot of code.

A long intro, but I hope it helps in understanding my questions. Is it possible to use the MvxGridView for this type of scenario? Or is there a different type of approach you would suggest with MvvmCross that would still allow me to keep the logic in viewmodel and model classes? If it's note too much too ask, a few code fragments would be really helpful.

I thought it might be possible by setting the android:layout_column and android:layout_row properties for a LinearLayout that is used as an ItemTemplate for an MvxGridView. I also read about using MvvmCross to bind layout_weight: How to bind to View's layout_weight in MvvmCross? However, I can't seem to find a way to access the layout_column and layout_row properties in the same way.

Thanks in advance for any help or suggestions you may be able to provide. I really like how the MvvmCross framework allows me to reuse many of my Windows store app programming skills. It would be great if I could use it for laying out the tiles in a grid, with or without the use of the MvxGridView.

Community
  • 1
  • 1
Inge
  • 1
  • I guess http://stackoverflow.com/questions/21477431/how-to-bind-to-views-layout-weight-in-mvvmcross could work - what have you tried there - is there code around "I can't seem to find a way"? Also, the question overall is possibly similar to http://stackoverflow.com/questions/15518009/most-user-friendly-option-for-layout-in-android-app. (Sorry - I don't think I have a suggested approach for the sliding grid UI right now - it's a custom UI and I would have to prototype it to get a feel for what might work) – Stuart Aug 27 '14 at 10:36
  • Thanks for the quick reply. The part where I get stuck is the SetValueImpl method in my custom MvxAndroidTargetBinding. I used this as an example: ViewGroup.LayoutParams layoutParameters = realTarget.LayoutParameters; realTarget.LayoutParameters = new LinearLayout.LayoutParams(layoutParameters.Width, layoutParameters.Height, (int) value); I am adding the binding to a LinearLayout: Android.Widget.LinearLayout.LayoutParams layoutParams = linearLayout.LayoutParameters; But I don't know how to set the layout_column and layout_row properties. Does this clarify my problem? – Inge Aug 27 '14 at 12:30
  • I think `LinearLayout` might be your problem in that description - try `GridLayout` instead? – Stuart Aug 27 '14 at 12:52
  • With your help I managed to locate the ColumnSpec and RowSpec properties. Unfortunately, I am running into all sorts of other problems. I don't think this solution is going to work for this scenario. I will have a look at your other proposed solution. If that doesn't work or gets too complicated, I am going to try a custom control, generating items manually. Thanks for your input, though. I learned a lot in the meantime. – Inge Aug 27 '14 at 14:56

0 Answers0