Hi, I have created controlled template to which I bind some properties. Then I have Main view which Is a page to which I need to bind one class to render realtime data.
Problem is that when I use bindablecontext=myclass; IT breaks the other databinding which goes to template.
Here is the code
<?xml version="1.0" encoding="utf-8" ?>
<Application"
xmlns:x=""
xmlns:custom="clr-namespace:HOT_App.Components"
x:Class="HOT_App.App">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="appLayout">
<!-- Template file -->
<!-- Grid definition -->
<Grid BackgroundColor="#e4e4e4" ColumnSpacing="0" RowSpacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions >
<RowDefinition Height="65"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.5*"></ColumnDefinition>
<ColumnDefinition Width="9*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- Children's of the grid. -->
<!-- Place for background. -->
<StackLayout BackgroundColor="#252a54" Grid.Row="0">
<BoxView HeightRequest="10" BackgroundColor="#009de0"></BoxView>
</StackLayout>
<!-- Place for logo and treatment profile. -->
<StackLayout Spacing="0" BackgroundColor="#252a54" Grid.Column="1">
<BoxView Margin="0" HeightRequest="10" BackgroundColor="#009de0"></BoxView>
<Grid Margin="0" Padding="0" BackgroundColor="#0f1d3f" ColumnSpacing="0" RowSpacing="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions >
<RowDefinition Height="55"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition ></ColumnDefinition>
<ColumnDefinition ></ColumnDefinition>
<ColumnDefinition ></ColumnDefinition>
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="#252a54" Grid.Column="0" Grid.ColumnSpan="3"/>
<Image Margin="0,-20" Grid.Column="1" TranslationY="10" TranslationX="-20" HorizontalOptions="Center" Source="o2matic_logo.png" />
<Frame Padding="3" Grid.Column="2" HorizontalOptions="End" HeightRequest="50" WidthRequest="150" BackgroundColor="#009de0">
<FlexLayout AlignItems="Center" JustifyContent="Center" WidthRequest="150" HeightRequest="50" BackgroundColor="#252a54" >
<Label WidthRequest="150" FontSize="20" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" Text="{TemplateBinding Parent.BindingContext.UserData.TreatmentProfile.TreatmentProfileName}" />
</FlexLayout>
</Frame>
</Grid>
</StackLayout>
<!-- Place for name, battery,navigation, udsn. -->
<StackLayout Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" >
<!-- Name -->
<Frame WidthRequest="225" BackgroundColor="#26272d" HeightRequest="105" TranslationX="-25" TranslationY="-25" CornerRadius="25"
Padding="0"
Margin="-25,0">
<Label TranslationX="25" TranslationY="10" FontSize="24" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" Text="{TemplateBinding Parent.BindingContext.UserData.FirstName}" />
</Frame>
<!--Battery-->
<Frame TranslationX="-25" WidthRequest="225" BackgroundColor="#26272d" CornerRadius="25"
Padding="0"
Margin="-25,0" TranslationY="-15">
<StackLayout TranslationX="20" Spacing="0">
<Label Margin="5" FontSize="Medium" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" Text="Battery"/>
<BoxView HeightRequest="2" Color="Gray"></BoxView>
<FlexLayout Direction="row" JustifyContent="Center" AlignContent="Center" AlignItems="Center">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<BoxView TranslationX="6" Margin="0,12" HorizontalOptions="Start" WidthRequest="{TemplateBinding Parent.BindingContext.BatteryStatus.BatteryLevelRenderer}" Grid.Column="0" Grid.Row="0" BackgroundColor="White" HeightRequest="50"/>
<Image WidthRequest="65" Grid.Column="0" Grid.Row="0" HorizontalOptions="Center" Source="battery.png" />
</Grid>
<Label Margin="10,0,0,0" FontSize="Large" TextColor="White" VerticalTextAlignment="Start" HorizontalTextAlignment="Center" Text="{TemplateBinding Parent.BindingContext.BatteryStatus.BatteryPercantage}"/>
</FlexLayout>
</StackLayout>
</Frame>
<!--Navigation-->
<Frame TranslationX="-25" WidthRequest="225" BackgroundColor="#26272d" VerticalOptions="FillAndExpand" CornerRadius="25" Margin="-25,0">
<StackLayout TranslationX="25">
<BoxView HorizontalOptions="Fill" BackgroundColor="Black" HeightRequest="2"/>
<!--Navigation loop-->
<ListView VerticalOptions="Start" SeparatorVisibility="Default" SeparatorColor="Black" RowHeight="50"
ItemsSource="{TemplateBinding Parent.BindingContext.AppNavigation.NavigationItems}">
<ListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<Grid ClassId="{Binding NavigationItemName}" HorizontalOptions="Center" >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="45" />
<RowDefinition Height="2" />
</Grid.RowDefinitions>
<Image WidthRequest="35" HorizontalOptions="End" VerticalOptions="Center" Source="{Binding Icon}" Grid.Row="0" Grid.Column="0"/>
<Label VerticalTextAlignment="Center" TextColor="White" FontSize="Large" HorizontalTextAlignment="Center" Text="{Binding NavigationItemName}" Grid.Row="0" Grid.Column="1"/>
<Image IsVisible="{Binding Active}" WidthRequest="25" HorizontalOptions="End" Source="activeNavigation.png" Grid.Row="0" Grid.Column="2"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer CommandParameter="{Binding NavigationItemName}" Tapped="NavigationHandler"/>
</Grid.GestureRecognizers>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!--Navigatio loop-->
<BoxView HorizontalOptions="Fill" BackgroundColor="Black" HeightRequest="2"/>
<Frame Padding="0" BackgroundColor="Transparent" WidthRequest="225" VerticalOptions="EndAndExpand" >
<StackLayout WidthRequest="225" HorizontalOptions="FillAndExpand" >
<BoxView HorizontalOptions="Fill" BackgroundColor="Black" HeightRequest="2"/>
<Label VerticalTextAlignment="Center" TextColor="White" FontSize="Default" HorizontalTextAlignment="Center" Text="UDSN"/>
<Label BackgroundColor="Gray" VerticalTextAlignment="Center" TextColor="White" FontSize="Default" HorizontalTextAlignment="Center" Text="{TemplateBinding Parent.BindingContext.deviceData.UDSN}"/>
</StackLayout>
</Frame>
</StackLayout>
</Frame>
</StackLayout>
<!-- Place for vital's, treatment, warnings. -->
<StackLayout Margin="10, 30, 10, 10" Grid.Row="1" Grid.Column="1">
<ContentPresenter></ContentPresenter>
</StackLayout>
</Grid>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using HOT_App.Services;
using HOT_App.Views;
using HOT_App.ViewModels;
using System.Collections.ObjectModel;
using ProgressBar = HOT_App.ViewModels.ProgressBar;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace HOT_App
{
public partial class App : Application
{
//TODO: Replace with *.azurewebsites.net url after deploying backend to Azure~~~~
public static bool UseMockDataStore = true;
Navigation AppNavigation = new Navigation();
Battery BatteryStatus = new Battery();
ApplicationBindings ApplicationBind { get; set; }
public App()
{
InitializeComponent();
TreatmentProfile treatmentProfile = new TreatmentProfile("2","COPD_NORal");
UserData UserData = new UserData("ID789456789","Matuska","English","Denmark","31858585","38585848", treatmentProfile);
DeviceData DeviceData = new DeviceData("UDSN12213213");
ApplicationBind = new ApplicationBindings(AppNavigation, BatteryStatus, UserData, DeviceData);
VitalsData VitalsData = new VitalsData(70, 6.1, 92);
BatteryStatus.BatteryLevelChange(50);
this.BindingContext = ApplicationBind;
if (UseMockDataStore)
DependencyService.Register<MockDataStore>();
else
DependencyService.Register<AzureDataStore>();
//this.BindingContext = AppNavigation;
MainPage = new NavigationPage(new Main());
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
// Navigation controler->>> works with AppNavigation<Navigation>
private void NavigationHandler(object sender, EventArgs e)
{
Grid gridSender = (Grid)sender;
if (gridSender.GestureRecognizers.Count > 0)
{
var gesture = (TapGestureRecognizer)gridSender.GestureRecognizers[0];
var activeNav = (string)gesture.CommandParameter;
AppNavigation.SetActiveNavigation(activeNav);
}
AppNavigation.ShowActiveNavigation();
}
}
}
MAin.cs
using HOT_App.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using ProgressBar = HOT_App.ViewModels.ProgressBar;
namespace HOT_App.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Main : ContentPage
{
public Main ()
{
InitializeComponent();
VitalsData VitalsData = new VitalsData(70, 6.1, 92);
this.SetBinding(BindableProperty.Create("AppBindings", typeof(Navigation), typeof(ApplicationBindings)), "AppBindings");
//this.SetBinding(BindableProperty.Create("BatteryStatus", typeof(Battery), typeof(Main), new Battery()), "BatteryStatus");
this.SetBinding(BindableProperty.Create("VitalsData", typeof(VitalsData), typeof(VitalsData), VitalsData), "VitalsData");
DateTime newMeasurementTime = new DateTime(2019, 07, 02, 13, 31, 30);
Measurement newMeasurement = new Measurement(newMeasurementTime, mainStackLayout);
newMeasurement.CreateCountdown();
//StackLayout testing=newMeasurement.DisplayCountdown_StartOfMeasurement();
//mainStackLayout.Children.Add(testing);
}
}
}~~~~