Issue
Im now working on my third beginner program in xamarin forms and want to programm an accelerometer
We know that the API Xamarin Essentials is doing the job with the calculation and all but when i insert something like Accelerometer.IsMonitoring it doesnt know about the IsMonitoring even it has to know about it what im doing wrong here is an eventhandler i defined in the xaml data and it doesnt recognize IsMonitoring and Start and gives me the error: the type or namespace name 'Start' doesnt exist in the namespace:Accelerometer
Here is the code:
private void ButtonStart_Clicked(object sender, EventArgs e)
{
if (Accelerometer.IsMonitoring)
return;
Accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
Accelerometer.Start(SensorSpeed.UI);
}
And this is the xaml code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.ColumnSpan="2" x:Name="LabelX"/>
<Label Grid.Row="1" Grid.ColumnSpan="2" x:Name="LabelY"/>
<Label Grid.Row="2" Grid.ColumnSpan="2" x:Name="LabelZ"/>
<Button Grid.Row="3" Grid.ColumnSpan="0" x:Name="ButtonStart" Text="Start" Clicked="ButtonStart_Clicked"/>
<Button Grid.Row="3" Grid.ColumnSpan="1" x:Name="ButtonStop" Text="Stop" Clicked="ButtonStop_Clicked"/>
</Grid>
What im doing wrong or what is missing
Solution
because your project is named Accelerometer
it cannot differentiate between your main App namespace and the Xamarin.Essentials Accelerometer
class
You can fix this by renaming your project, or creating an alias for Xamarin Essentials, or fully qualifying the classname like this
private void ButtonStart_Clicked(object sender, EventArgs e)
{
if (Xamarin.Essentials.Accelerometer.IsMonitoring) return;
Xamarin.Essentials.Accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
Xamarin.Essentials.Accelerometer.Start(SensorSpeed.UI);
}
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.