Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

ContentView xaml properties not updating

$
0
0

Hello.
I've been trying to make a Calendar Control for an app I am developing.
I created a ControlView with its .xaml and I am trying to set a property in the xaml of the page that is consuming the control, like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:app2="clr-namespace:App2"
             mc:Ignorable="d"
             x:Class="App2.MainPage">
    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="0">
        <app2:CalendarControl x:Name="clControl" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" EsSemanal="True"></app2:CalendarControl>
    </StackLayout>

</ContentPage>

I set the "EsSemanal" property to true to tell the calendar to render in week mode.
My "CalendarControl" .cs:

public partial class CalendarControl : ContentView
    {
        public static readonly BindableProperty EsSemanalProperty = BindableProperty.Create(nameof(EsSemanal), typeof(bool), typeof(CalendarControl), false);
        public bool EsSemanal
        {
            get => (bool)GetValue(EsSemanalProperty);
            set => SetValue(EsSemanalProperty, value);
        }
...
}

So in the constructor I render the control:

public CalendarControl()
        {
            InitializeComponent();
            if (!EsSemanal)
            {
                //Cargamos diseño de calendario diario
                Grid gridDiaria = new Grid();
                gridDiaria.VerticalOptions = LayoutOptions.FillAndExpand;
                gridDiaria.SetValue(Grid.RowProperty, 1);
                gridDiaria.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) });
                gridDiaria.RowDefinitions.Add(new RowDefinition { Height = new GridLength(8, GridUnitType.Star) });
                //Label con el día
                Label lbDia = new Label();
                lbDia.HorizontalOptions = LayoutOptions.CenterAndExpand;
...
        }
    }

The problem is that when the constructor gets called, the "EsSemanal" property is still set to the default value.
It is not updating.
Is there any way of making the value update before the constructor gets called or what are some good strategies of approaching this?

Thank You.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>