OnPlatform Template Binding

jb_tcjb_tc ✭✭USMember ✭✭

Hi,

I try to add an Progressbar for iOS only. So I use "OnPlatform".

<tccontrols:ExtendedProgressBar 
    Grid.Row="0" 
    Grid.Column="0" 
    BackgroundColor="#f2dbba" 
    BarColor="#f49712" 
    HeightRequest="2.5" 
    HorizontalOptions="FillAndExpand" 
    Progress="{TemplateBinding PageLoadingProgress}">

    <tccontrols:ExtendedProgressBar.IsVisible>
        <OnPlatform
             x:TypeArguments="x:Boolean" 
             iOS="{TemplateBinding ShowLoadingBar}"
             Android="false"/> 
    </tccontrols:ExtendedProgressBar.IsVisible>

</tccontrols:ExtendedProgressBar>

This is, what my "ShowLoadingBar" looks like:

public static readonly BindableProperty ShowLoadingBarProberty =
      BindableProperty.Create("ShowLoadingBar", typeof(Boolean), typeof(TC.App.Page.ExtendedWebViewPage), false);

And I got this error:

Position 70:38. Cannot assign property "iOS": Property does not exists, or is not assignable, or mismatching type between value and property

If I use that TemplateBinding as normal attribute IsVisible="{TemplateBinding ShowLoadingBar}" it works finde...

What is wrong? Where is my mistake?

Tagged:

Best Answers

  • NMackayNMackay mod GB mod
    edited December 2017 Accepted Answer

    @jb_tc said:
    @NMackay
    It is still not working. With x:TypeArguments="Boolean" I got this message: Position 68:34. Type Boolean not found in xmlns http://xamarin.com/schemas/2014/forms
    If I am using x:TypeArguments="x:Boolean" I got this message Exception has been thrown by the target of an invocation.

    Any Idea?

    Thank you so much!!

    I made a typo, forgot x:

    <tccontrols:ExtendedProgressBar.IsVisible>
        <OnPlatform x:TypeArguments="x:Boolean">
                                      <On Platform="iOS">{TemplateBinding ShowLoadingBar}</On>
                                      <On Platform="Android">false</On>
           </OnPlatform>
    </tccontrols:ExtendedProgressBar.IsVisible>
    

Answers

  • NMackayNMackay mod GBInsider, University mod
    edited December 2017

    Try:

    <tccontrols:ExtendedProgressBar.IsVisible>
        <OnPlatform x:TypeArguments="Boolean">
                                      <On Platform="iOS">{TemplateBinding ShowLoadingBar}</On>
                                      <On Platform="Android">false</On>
           </OnPlatform>
    </tccontrols:ExtendedProgressBar.IsVisible>
    
  • jb_tcjb_tc ✭✭ USMember ✭✭

    @NMackay
    It is still not working. With x:TypeArguments="Boolean" I got this message: Position 68:34. Type Boolean not found in xmlns http://xamarin.com/schemas/2014/forms
    If I am using x:TypeArguments="x:Boolean" I got this message Exception has been thrown by the target of an invocation.

    Any Idea?

    Thank you so much!!

  • NMackayNMackay mod GBInsider, University mod
    edited December 2017 Accepted Answer

    @jb_tc said:
    @NMackay
    It is still not working. With x:TypeArguments="Boolean" I got this message: Position 68:34. Type Boolean not found in xmlns http://xamarin.com/schemas/2014/forms
    If I am using x:TypeArguments="x:Boolean" I got this message Exception has been thrown by the target of an invocation.

    Any Idea?

    Thank you so much!!

    I made a typo, forgot x:

    <tccontrols:ExtendedProgressBar.IsVisible>
        <OnPlatform x:TypeArguments="x:Boolean">
                                      <On Platform="iOS">{TemplateBinding ShowLoadingBar}</On>
                                      <On Platform="Android">false</On>
           </OnPlatform>
    </tccontrols:ExtendedProgressBar.IsVisible>
    
  • jb_tcjb_tc ✭✭ USMember ✭✭
    edited December 2017

    @NMackay
    it is still not working...

    As I wrote, I got an exception:

    If I am using x:TypeArguments="x:Boolean" I got this message "Exception has been thrown by the target of an invocation."

    Any Idea?

    Thank you!

  • NMackayNMackay mod GBInsider, University mod

    @jb_tc

    There's nothing wrong with the syntax, the template binding part in OnPlatform might not work though, that thought did cross my mind. For example, take out the template binding and just use a boolean value and it should compile fine. I have to admit I haven't had to do it but perhaps in this case you may have to use a ValueConverter.

    https://forums.xamarin.com/discussion/76850/is-it-possbile-to-bind-a-specific-property-value-with-onproperty
    https://bugzilla.xamarin.com/show_bug.cgi?id=44213

  • jb_tcjb_tc ✭✭ USMember ✭✭

    @NMackay Thank you so much!!!!

    x:TypeArguments="BindingBase"did it for me. Perfect.

    Thank you again!!

    <tccontrols:ExtendedProgressBar 
                                Grid.Row="0" 
                                Grid.Column="0" 
                                BackgroundColor="#f2dbba" 
                                BarColor="#f49712" 
                                HeightRequest="2.5" 
                                HorizontalOptions="FillAndExpand" 
                                Progress="{TemplateBinding PageLoadingProgress}">
    
                                <tccontrols:ExtendedProgressBar.IsVisible>
                                    <OnPlatform x:TypeArguments="BindingBase">  
                                        <On Platform="iOS" Value="{TemplateBinding ShowLoadingBar}"/>
                                        <On Platform="Android" Value="false" />
                                    </OnPlatform> 
                                </tccontrols:ExtendedProgressBar.IsVisible>
    
                            </tccontrols:ExtendedProgressBar>
    
    
  • NMackayNMackay mod GBInsider, University mod

    @jb_tc

    Excellent, had to pick through a few posts and bugzilla's to find that one :smile:

Sign In or Register to comment.