Grid row height TemplateBinding throwing exception

Raihan Iqbal 121 Reputation points

I'm trying to hide a row of a Grid in my ControlTemplate based on the value of a boolean BindableProperty.



    <ControlTemplate x:Key="HeaderWithNavigation">
                <Grid x:Name="HeaderWithNavigationGrid">
                        <RowDefinition Height="0.1*" />
                        <RowDefinition Height="0.8*" />
                        <RowDefinition Height="{TemplateBinding ShowFooter, Converter={StaticResource GridRowVisibilityConverter}}" />



The ShowFooter is defined as such:

public static readonly BindableProperty ShowFooterProperty = BindableProperty.Create(nameof(ShowFooter), typeof(bool), typeof(MyDefaultTemplatePage), default(bool));
        public bool ShowFooter
            get => (bool)GetValue(ShowFooterProperty);
            set => SetValue(ShowFooterProperty, value);

I borrowed the coverter from here. I dont get any compilation errors but when I load the page that uses this template, the app crashes with a System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,287 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,936 Reputation points


    Welcome to our Microsoft Q&A platform!

    I tested your code in a basic demo and faced the same issue. It's caused by the limit of TemplateBinding, check this link. To fix this issue, try using Binding instead.

       <ControlTemplate x:Key="_template">  
                   <RowDefinition Height="25" />  
                   <RowDefinition Height="35" />  
                   <RowDefinition Height="{TemplateBinding IsShowing, Converter={StaticResource _converter}}" />  

    Best Regards,

    Jarvan Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful