Xamarin Forms: Public C# Properties Missing on Android

While working on the mobile apps for McAllen Next (my new side project, stay tuned for more soon!), I discovered a very strange issue when running the app on Android; I kept getting repeated errors like this:

Binding: ‘IsLoading’ property not found on ‘RegionModel’, target property: ‘Xamarin.Forms.Label’

and as such, the UI would not bind and would render an empty label (or not at all, depending on the control).

At first I thought it was because the app wasn’t rebuilding properly, resulting in stale binaries as was suggested in a StackOverflow post I found while trying to find a fix.

Eventually I posted my own question about this issue and I swear before two minutes passed, I was provided the solution by a very helpful user Gusman.

Turns out I had the box checked in the Android properties for the project to link both SDK and User assemblies.


Apparently this optimizes the selected assemblies, removing references to properties that the linker detects are not in use.

I don’t remember much from my college days when we built a compiler, but although optimization sounds great, completely deleting references is strange to me, especially if they’re going to be bound at runtime to the XAML as they are when working with Xamarin Forms…

But hey I’m not a compiler builder, so I changed the option to only link SDK assemblies, and everything is back to normal!

As always, I hope this is helpful, and thanks for reading!

Quick Fix: Unwanted Rounding When String Formatting Number as Currency

Sometimes it’s the little things you forget the easiest and most often that throw you for a loop. Today I was attempting to show a value in an ASP.NET MVC View which is stored as type long, representing a monetary amount in cents.

I formatted it as currency:

@string.Format("{0:c}", Model.Subtotal / 100)

But when I saw the output it rounded the value of 1250 to $12.00. This was strange since it was rounding down instead of up, which would still be incorrect, but at least make sense.

In an attempt to fix, I added a decimal place to the formatting:

@string.Format("{0:c2}", Model.Subtotal / 100)

But apparently currency is already set to two decimals. I can add more decimals, but it will always be zero, since it’s rounding.

I then realized that the Subtotal is long, which is an integer, as is of course 100, so it’s doing integer division. I need to cast one of the values to ensure the result doesn’t round. I defined the 100 value as a decimal by adding M at the end:

@string.Format("{0:c}", Model.Subtotal / 100M)

which revealed the expected output of $12.50 and I can go about my day.

It’s all so obvious in retrospect, but it’s one of those things that is easily forgotten. hopefully this note will help me remember!

as always, hope this was helpful and thanks for reading!

Windows 10 Development: Custom StateTriggers

We’ve seen how the Windows 10 AdaptiveTrigger can help you create a dynamic responsive UI based on the height or width of the device or screen. However, this trigger is limited to a specific value for each dimension, and offers no way to respond to changes in the relationship between them, such as to determine the orientation or aspect ratio of the app.

Fortunately, you are not limited to only the AdaptiveTrigger in Windows 10; you can create your own custom statetriggers based on virtually any property, even those not at all related to the UI. In this post, we’ll look at how we combined both the width and orientation properties of the app to create a custom OrientationSize trigger to switch between visual states using these properties.

Read more at the Falafel Software Blog: Windows 10 Development: Custom StateTriggers

Windows 10 Development: Responsive Design with AdaptiveTriggers

In the previous post we looked at the basics of UI automation in Windows 10 apps using Blend to declare the XAML for Visual States. However, while last time we used event handlers in the code-behind of a page to trigger different states, this time we’ll see how to use the new AdaptiveTriggers in Windows 10 to let the application handle state transitions automatically.

Read more at the Falafel Software Blog: Windows 10 Development: Responsive Design with AdaptiveTriggers

Windows 10 Development: SplitView

Now that we have a simple but solid foundation for a complete Windows 10 app, let’s take a tour through some of the brand new controls available on the platform. Today we’ll look at the SplitView control, which enables you to quickly create a consistent, intuitive navigation UI that can automatically adjust to different screen sizes and device platforms.

Read more at the Falafel Software Blogs: Windows 10 Development: SplitView

Windows 10 Development: MvvmLight NavigationService and the Behaviors SDK

Following our last post, we now have a solid framework for our app to handle state and lifecycle. However, at this point we are still navigating the app directly from the code-behind of the Views, which ties the navigation to the platform code. In addition to not cluttering up our code, this also restricts us from fully taking advantage of the cross-platform opportunities offered by MvvmLight.

Today we’ll see how to centralize this navigation code, removing the platform-specific definition and moving from the code-behind to the ViewModels, allowing maximum reuse of code. We’ll begin with the code related to navigation.

Read more on the Falafel Software Blogs: Windows 10 Development: MvvmLight NavigationService and the Behaviors SDK

Windows 10 Development: Maintaining Application State

We have so far created a simple app with two pages, that uses simple Frame navigation to go back and forth. However, the app is still missing one crucial feature: state management. When an app is suspended for whatever reason (such as being minimized on the desktop or navigated away from on the phone), it is up to the developer to maintain the current state so that it can be fully restored where the user left off.

In this post we’ll look at a simple way we can achieve this by leveraging helper classes from the Windows 8.1 project templates.

Read more at the Falafel Software Blogs: Windows 10 Development: Maintaining Application State>