Skip to main content

Posts

Showing posts from 2017

Xamarin.Form's autosized label

Please see Sabon Rai Software's solution here: https://sabonrai.wordpress.com/2016/02/14/xamarin-forms-xaml-label-adjusts-font-size-to-fit-width-of-content/#comment-3002

In short, the AutosizeLabelRenderer code looks like this:


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21[assembly: ExportRenderer (typeof(AutosizeLabel), typeof(AutosizeLabelRenderer))]namespace<NAMESPACE>{publicclassAutosizeLabelRenderer:LabelRenderer{protectedoverridevoidOnElementChanged(ElementChangedEventArgs<Label>e){base.OnElementChanged(e);varlabel=ControlasUILabel;if(label!=null){label.AdjustsFontSizeToFitWidth=true;label.Lines=1;label.BaselineAdjustment=UIBaselineAdjustment.AlignCenters;//label.LineBreakMode = UILineBreakMode.Clip;label.MinimumScaleFactor=newSystem.nfloat(0.5);}}}}

Xamarin.Forms: making the switch control MVVM compliant

The switch control out of the Xamarin.Forms toolbox does not appear to be MVVM compliant. That means that its toggle (as a result of a UI tap) changes the state of the switch w/o validating or asking the Model (via the ViewModel) if it should change its state. I tried handling a "toggling" event or subclassing the switch but was unable to find a OOP solution to this problem. Instead I disabled the control and handled the ItemSelected event on the listView which first validates and then changes the state of the IsToggledProperty binding property. The disadvantage of incorrectly using the IsEnabled property is dimming an otherwise active control but at this point I'm able to live w/ this downside.

Microsoft's mobile center w/ xamarin.forms

Mobile center is a great and easy add-on to your xamarin.forms apps. It provides crash and usage analytics as well as push notifications and a distribution/testing framework. You just have to install a few nuget packages and add a few lines to start mobile center. One gotcha on the push notification component - it does not work in the iOS simulator. For those that got here from google and want to know why Push.IsEnabledAsync() returns false - note that you can not get notifications in the iOS simulator.

References:
https://mobile.azure.com
https://www.visualstudio.com/vs/mobile-center/

Let's talk about style...

Placeholder, will discuss:
global and implicit/explicit styles status bar and tabbed page colors (back/foreground)banded alternating rows Reference:
Xamarin styling: https://blog.xamarin.com/easy-app-theming-with-xamarin-forms-styles Microsoft colors: https://msdn.microsoft.com/en-us/library/aa358802(v=vs.85).aspx

Xamarin.Forms BindableProperty's unintuitive getter/setter properties

Apparently you cannot debug (or break into) these getter/setter properties of a BindableProperty and instead are advised to implement a propertyChanged event on the BindableProperty.
I made a userControl (as a refactored view w/in a view) and wanted to pass two bindable contexts to separate views w/in the parent view; something like this:


1 2<lv:MasterDetailArrableViewGrid.Row="1"Grid.Column="0"Grid.ColumnSpan="2"MasterArrable="{Binding FieldSelectionKeys}"DetailArrable="{Binding FieldSelectionFields}"/>
I decided to implement this by setting the internal view's BindingContext when the respective properties are set. However you cannot simply overwrite the MasterArrable setter and instead are advised to catch the propertyChanged event and do your work there. For example, the MasterArrable BindableProperty code looks like this:


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20publicstaticreadonlyBindablePropertyMasterAr…

Xamarin.Forms persistance (aka save/load local settings)

I just learned and implemented how to persist local settings for a xamarin.forms app. At first read, I noticed that xamarin.forms Application.Current.Properties supports this functionality but I wasn't able to figure it out. Usually I like to use default functionality when available but this simple API was not working for me. So I did some research and found a bunch of alternatives from James Montemagno's settings plugin to the realm mobile database. For my simple needs at this time, I nuget'ed the settings plugin and had it working in 2-3m (only because I spent a minute reading the GettingStarted.html). The code is simple and looks like:

Save:
CrossSettings.Current.AddOrUpdateValue("Securities", _addedSecurities.ToFlatFile(','));

Load:
protected override void OnStart()
{
string securitiesCsv = CrossSettings.Current.GetValueOrDefault("Securities", string.Empty);
}

Xamarin.Forms OnPlatform - TabbedPage vs NavigationPage

I switched my start page from a NavigationPage to a TabbedPage and all of a sudden the content overwrote the the carrier/battery row. I looked into this and discovered that the TabbedPage does not offset itself below this header in iOS (but works for android and windows). The solution is to add a platform dependent offset or padding thickness of 20 pixels.

dbapps.com: top 200 iOS apps

Repurposed dbapps.com to present the iOS app data I've collected over the years. It shows the top 200 FREE, PAID, and GROSSING iOS apps on the apple app store along w/ their deltas over several time periods. I've used this report to help guide my investments in the mobile app space. Here's a screenshot:


Hi again.

As a programmer working on my own startup, every day brings new challenges in the areas of software development and infrastructure. I had to explore and implement infrastructures that are suitable for my development needs and learn new technologies that I'm pursuing as part of my startup. I'm learning a lot from googling and want to give back by journal'ing roadblocks I overcome..

Two near-future posts I've been collecting data about are 1. building something resembling a "datagrid" in xamarin forms that binds to a List<Dictionary> and 2. implementing a continuous integration development environment.