Default Value for OnPlatform

StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭
edited April 19 in Xamarin.Forms Evolution

Summary

The old OnPlatform mechanism used to pick the iOS value as default for a non-specified platform. The new (as of 2.3.4) mechanism doesn't do that and instead returns default(T). This means that when you try to get your code running in a new platform, most of the OnPlatform uses will return an inappropriate value.

The issue is only present in XAML, as the recommended way of doing platform switch in c# is to use a switch statement (https://github.com/xamarin/Xamarin.Forms/pull/658#issue-196972349).

This has been pointed out here: https://github.com/xamarin/Xamarin.Forms/pull/658#issuecomment-294400530

API Changes

Added

public T OnPlatform<T>.Default { get; set; }

Intended Use Case

<ToolbarItem Clicked="Save_Clicked" >
    <ToolbarItem.Text>
        <OnPlatform x:TypeArguments="x:String" Default="Save">
            <On Platform = "iOS" Value="Done" />
        </OnPlatform>
    </ToolbarItem.Text>
</ToolbarItem>
0
0 votes

Accepted · Last Updated

Posts

Sign In or Register to comment.