Forum Xamarin.Forms

ControlTemplate TemplateBinding : Operation is not valid due to the current state of the object.

toyinstoyins USMember ✭✭✭
edited July 2019 in Xamarin.Forms

I Have a ControlTemplate in my App.Xaml to be used across pages.
All the TemplateBindings work within the ControlTemplate, except the ones within the ColumnDefinitions of the Grid.
Here's the Xaml

            <ControlTemplate x:Key="CommonPageTemplate">
            <Grid RowSpacing="0" 
                  BackgroundColor="Black">
                <Grid.RowDefinitions>
                    <RowDefinition>
                        <RowDefinition.Height>
                            <OnPlatform x:TypeArguments="GridLength">
                                <On Platform="iOS" Value="0.06*" />
                                <On Platform="Android,UWP" Value="0.06*" />
                            </OnPlatform>
                        </RowDefinition.Height>
                    </RowDefinition>
                    <RowDefinition>
                        <RowDefinition.Height>
                            <OnPlatform x:TypeArguments="GridLength">
                                <On Platform="iOS" Value="0.83*" />
                                <On Platform="Android,UWP" Value="0.83*" />
                            </OnPlatform>
                        </RowDefinition.Height>
                    </RowDefinition>
                    <RowDefinition>
                        <RowDefinition.Height>
                            <OnPlatform x:TypeArguments="GridLength">
                                <On Platform="iOS" Value="0.11*" />
                                <On Platform="Android,UWP" Value="0.11*" />
                            </OnPlatform>
                        </RowDefinition.Height>
                    </RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{TemplateBinding Parent.CommonPageColumnDef1}" />
                    <ColumnDefinition Width="{TemplateBinding Parent.CommonPageColumnDef2}" />
                    <ColumnDefinition Width="{TemplateBinding Parent.CommonPageColumnDef2}" />
                </Grid.ColumnDefinitions>

                <!--<BoxView Grid.ColumnSpan="3" Color="Black" />-->
                <Image  Grid.ColumnSpan="3" Grid.Row="0" Grid.Column="0"
                        Source="{e:ImageMultiResource MyApp.Assets.Images.CommonImages.navbar}" 
                        Aspect="AspectFill"/>

                <StackLayout Grid.Row="0" 
                             Grid.Column="0"
                             IsVisible="{TemplateBinding Parent.AboutButtonIsVisible}"
                             Padding="{TemplateBinding Parent.AboutButtonPadding}">
                    <controls:AboutImageButton  
                                               VerticalOptions="Center" 
                                               HorizontalOptions="Start"
                                               AboutButtonIsVisible="{TemplateBinding Parent.AboutButtonIsVisible}"
                                               AboutButtonCommand="{TemplateBinding Parent.GoToAboutPageCommand}"/>
                </StackLayout>

                <Label Grid.Row="0" Grid.Column="1" 
                       Text="{TemplateBinding Parent.PageTitle}" 
                       Style="{StaticResource HeaderLabelStyle}" 
                       HorizontalOptions="Center"
                       VerticalOptions="Center"
                       Margin="{TemplateBinding Parent.CommonPageTemplatePageTileLabelMargin}">
                </Label>
                <StackLayout Grid.Row="0" 
                             Grid.Column="2">
                    <StackLayout.Padding>
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="iOS" Value="50,0,0,0" />
                            <On Platform="Android,UWP" Value="20,0,0,0" />
                        </OnPlatform>
                    </StackLayout.Padding>
                    <Button  
                        Style="{StaticResource SettingsButtonStyle}" 
                        VerticalOptions="Center"
                        HorizontalOptions="Center"
                        IsVisible="{TemplateBinding Parent.SettingsButtonIsVisible}"
                        IsEnabled="{TemplateBinding Parent.SettingsButtonIsEnabled}"
                        WidthRequest="{TemplateBinding Parent.SettingsButtonWidth}"
                        Command="{TemplateBinding Parent.GoToSettingsPageCommand}"
                        Text="{TemplateBinding Parent.SettingsText}"
                        Margin="{TemplateBinding Parent.SettingsButtonMargin}">
                        <Button.Padding>
                            <OnPlatform x:TypeArguments="Thickness">
                                <On Platform="iOS" Value="0,0,0,0" />
                                <On Platform="Android,UWP" Value="0,0,0,0" />
                            </OnPlatform>
                        </Button.Padding>
                        <Button.HeightRequest>
                            <OnPlatform x:TypeArguments="x:Double">
                                <On Platform="iOS" Value="23" />
                                <On Platform="Android,UWP" Value="28" />
                            </OnPlatform>
                        </Button.HeightRequest>
                    </Button>
                </StackLayout>
                <ContentPresenter Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" />
                <controls:CustomBottomBar Grid.Column="0" Grid.Row="2" HeightRequest="60" Grid.ColumnSpan="3"
                                          HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand"/>

            </Grid>
        </ControlTemplate>

How do I resolve this issue for these TemplateBindings in the Grid.ColumnDefinitions?

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    This is a general error which could be caused by kinds of reasons.

    Would you mind sharing us a basic sample project for reproduce the issue?

  • toyinstoyins USMember ✭✭✭
    edited July 2019

    @ColeX ,
    Here is the Xaml for the Page that I'm working on.

    Please let me know if this helps.

                <?xml version="1.0" encoding="utf-8" ?>
                <d:ContentPageBase xmlns="http://xamarin.com/schemas/2014/forms"
                             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                             xmlns:d="clr-namespace:MyApp;assembly=MyApp"
                             x:Class="MyApp.Page1"
                             xmlns:o="clr-namespace:Octane.Xamarin.Forms.VideoPlayer;assembly=Octane.Xamarin.Forms.VideoPlayer"
                             xmlns:markupExtensions="clr-namespace:MyApp.MarkupExtensions;assembly=MyApp"
                             PageTitle="Page 1"  
                             AboutText="{Binding AboutText}" 
                             AboutButtonWidth="{Binding AboutButtonWidth}" 
                             AboutButtonMargin="{Binding AboutButtonMargin}" 
                             AboutButtonIsVisible ="{Binding AboutButtonIsVisible}"
                             GoToAboutPageCommand ="{Binding GoToAboutPageCommand}"
                             SettingsText="{Binding SettingsText}" 
                             SettingsButtonWidth="{Binding SettingsButtonWidth}" 
                             SettingsButtonIsVisible ="{Binding SettingsButtonIsVisible}"
                             GoToSettingsPageCommand ="{Binding GoToSettingsPageCommand}"
                             BackgroundColor="Black"
                             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
                             ios:Page.UseSafeArea="true">
                    <ContentView x:Name="ContentView"  ControlTemplate="{StaticResource CommonPageTemplate}" >
                        <!--<StackLayout Margin="0,0,0,0" 
                                     BackgroundColor="Green" 
                                     Orientation="Vertical">-->
                            <o:VideoPlayer x:Name="Player1" 
                                           Margin="0"
                                           Source="{markupExtensions:VideoResource Circle.mp4}"  
                                           DisplayControls="False" 
                                           AutoPlay="True" 
                                           Repeat="True" 
                                           Volume="0" 
                                           IsVisible="True"
                                           FillMode="ResizeAspectFill"/>
                        <!--</StackLayout>-->
                    </ContentView>
                </d:ContentPageBase>
    
Sign In or Register to comment.