Hello everyone!
I have problem with transmit parameter via XAML between C# code and Controls (Skiasharp).
When I make change control parameters in XAML from C# code, I don't get them on the controls.
Please help me understand how to pass parameters correctly C# -> XAML -> Skiasharp controls.
I have problem with transmit parameter via XAML between C# code and Controls (Skiasharp).
When I make change control parameters in XAML from C# code, I don't get them on the controls.
Please help me understand how to pass parameters correctly C# -> XAML -> Skiasharp controls.
SensorPage.xaml:
<ContentPage x:Class="MobApp.Client.SensorCheck"
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:controls="clr-namespace:MobApp.Client.Controls"
NavigationPage.HasNavigationBar="false"
Visual="Material"
mc:Ignorable="d">
<StackLayout Orientation="Vertical">
<controls:SensorCheck Grid.Row="1"
x:Name="Sensor"
VerticalOptions="CenterAndExpand"
SensorState="WAIT"
/>
</StackLayout>
</ContentPage>
SensorPage.xaml.cs:
namespace MobApp.Client
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SensorCheck : ContentPage
{
public SensorCheck()
{
InitializeComponent();
Sensor.BindingContext = this;
SensorState = "READY";
}
}
#region Properties
public static readonly BindableProperty SensorStateProperty =
BindableProperty.Create("SensorState", typeof(string), typeof(SensorCheck), "");
public string SensorState
{
get { return (string)GetValue(SensorStateProperty); }
set { SetValue(SensorStateProperty, value); }
}
#endregion
SensorCheck.cs (Skiasharp):
namespace MobApp.Client.Controls
{
public class SensorCheck : SKCanvasView
{
public SensorCheck()
{
}
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
var val = SensorState;
// some code....
}
#region Properties
public static readonly BindableProperty SensorStateProperty =
BindableProperty.Create("SensorState", typeof(string), typeof(SensorCheck), "");
public string SensorState
{
get { return (string)GetValue(SensorStateProperty); }
set { SetValue(SensorStateProperty, value); }
}
#endregion
protected override void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == SensorStateProperty.PropertyName)
{
InvalidateSurface();
}
}
}
}