How to draw on a Skiasharp canvas with a tap using SKTouchEventArgs - xamarin.forms

I have a Skiasharp canvas that I want to draw markers on when I tap the image. I have this code:
<skia:SKCanvasView Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="3"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
EnableTouchEvents="True"
Touch="MarkDamage">
<!-- The Behaviours element binds the canvas to a command responsible for drawing in it. -->
<skia:SKCanvasView.Behaviors>
<behaviour:PaintSurfaceCommandBehavior Command="{Binding ShowDamageScreenCommand}" />
</skia:SKCanvasView.Behaviors>
</skia:SKCanvasView>
Note the Touch=MarkDamage attribute. That successfully binds to this method:
public void MarkDamage(object sender, SKTouchEventArgs e)
According to this answer, all the things I need to draw on my canvas are inside the parameters I'm passed. But I'm struggling to see how. All I want to do is draw a really simple circle on my canvas when I tap it.

Related

CarouselView Snap Points Alignment not working in Xamarin

I am using CarouselView to display data, do I use SnapPointsAlignment property for it:
<CarouselView x:Name="_data" PeekAreaInsets="40" ItemsUpdatingScrollMode="KeepItemsInView" HorizontalScrollBarVisibility="Never" VerticalScrollBarVisibility="Never">
<CarouselView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal" SnapPointsType="Mandatory" SnapPointsAlignment="Start" />
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
.....
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
I made AutoPlay for it:
...
Device.StartTimer(TimeSpan.FromSeconds(6), (Func<bool>)(() =>
{
_data.Position = (_data.Position + 2) % _listProd.Count;
return true;
}));
In the example I use SnapPointsAlignment="Start". However when I display my first data it stays in the middle. I searched in the documentation. However, still not found the solution described
What I look forward to
Note that I don't want to use CollectionView, because I have a hard time looping it
I am using XF 5.0.0.2291. Looking forward to everyone's help. Thank you

Disable click event on clipped area from cornered button

I have created a button and added pressed event on it. The button height and width are 300x300 and the corner radius is 150. So it looks like circle.
<Button
WidthRequest="300"
HeightRequest="300"
BackgroundColor="Red"
VerticalOptions="Center"
Margin="20,0,20,0"
HorizontalOptions="CenterAndExpand"
CornerRadius="150">
<Button.Behaviors>
<behaviors:EventToCommandBehavior EventName="Pressed"
Command="{Binding ButtonPressedCommand}" />
</Button.Behaviors>
</Button>
The issue is when I click blue area it cahtches pressed event. I want blue area to not catch the event. Now it detects the button as square, not as circle.
Broadly speaking, you shouldn't do that. The touch input is imprecise and unless your button is particularly huge those blue areas on your pic are within the bounds of the imprecise measurement and as such should be treated in that way.
If you really need this, you may try with MR.Gestures.AbsoluteLayout. Here is an example where it provides the exact point that the user has tapped: https://devtut.github.io/xamarin/gestures.html#place-a-pin-where-the-user-touched-the-screen-with-mr-gestures
For iOS, you can create a custom class which inherites UIButton and override the method PointInside.
class CustomiOSButton : UIButton
{
public override bool PointInside(CoreGraphics.CGPoint point, UIKit.UIEvent uievent)
{
bool flag = base.PointInside(point, uievent);
if (flag)
{
UIBezierPath path = UIBezierPath.FromOval(this.Bounds);
if (path.ContainsPoint(point))
{
return true;
}
}
return false;
}
}

GroupShortNameBinding adds a bullet point - how to remove

I have enabled Grouping on a list in iOS and added an Alphabet index to each entry
However, even though it displays the letters correctly, it's showing me a bullet point delimeter between each one?
I want to get rid of these, can anyone advise how please?
<ListView ItemsSource="{Binding allGames}" IsGroupingEnabled="True" GroupShortNameBinding="{Binding LETTER}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label TextColor="Black" Text="{Binding GAME_NAME}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Code for adding the index key (alphabet) to the list
if (allGames == null)
{
allGames = new ObservableCollection<GAME_TBL>();
}
var services = new DataModels();
GAME_SELECTION _select = new GAME_SELECTION();
allGames = await services.Games(1, _select);
foreach (GAME_TBL _indexTable in allGames)
{
_indexTable.LETTER = _indexTable.GAME_NAME.Substring(0, 1);
}
You can't remote the so-called "bullet points" - that is by design. The official term for that part is called Jump list.
What is happening behind the scenes is that you have too many grouped items. In this case, sometimes the phone's height can't fit all of them, so it is hiding some of the items behind the dots.
You can customize the list - change its color, etc, but the bullets can't be removed. However, what you can do is to reduce the count of your items, because I see some that are repeating - you have 3xS & 2xT, etc. If that is by design, then leave it like so. If not, try to better group the items.

how to change Height of Calendar control in Xamarin form?

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LeaveManagerApp.UpcomingLeavesPage"
xmlns:controls="clr- namespace:XamForms.Controls;assembly=XamForms.Controls.Calendar"
>
<Grid >
<controls:Calendar
x:Name="MyLeaveCalendar"
ShowNumberOfWeek="false"
StartDay="Sunday"
WeekdaysBackgroundColor="DarkBlue"
TitleLabelTextColor="DarkBlue"
SelectedDate="{Binding Date}"
SpecialDates="{Binding Attendances}"
DateCommand="{Binding DateChosen}"
>
</controls:Calendar>
</Grid>
How to fit calendar to screen size in xamarin form ,
i am using calendar control of xamarin form ,tried HeightRequest but its not working.
This is not a default Xamarin.Forms control, it originates from here: https://github.com/rebeccaXam/XamForms.Controls.Calendar
It looks like the control is rendered with a fixed height. Searching through the issues, I found this one: https://github.com/rebeccaXam/XamForms.Controls.Calendar/issues/54
You can influence the height of a row with this code:
yourCalendar.OnEndRenderCalendar += (sender, e) =>
{
(calendar.Content as StackLayout).Children.Last().HeightRequest = 500;
};
The only thing you need to do is determine the right height, build something yourself for it or open an issue on the repo.
You should post a full XAML code but as per Xamarin standard how to expand full view of child control. Check the below code.
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<controls:Calendar
x:Name="MyLeaveCalendar"
ShowNumberOfWeek="false"
StartDay="Sunday"
WeekdaysBackgroundColor="DarkBlue"
TitleLabelTextColor="DarkBlue"
SelectedDate="{Binding Date}"
SpecialDates="{Binding Attendances}"
DateCommand="{Binding DateChosen}"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
</controls:Calendar>
</Grid>
And also it's depend on Xamarin Layout which layout you are using for XAML design. And how to use XAML extensible language in Xamarin form Please check the link.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/

Xamarin.Forms: ListView inside StackLayout: How to set height?

In a ContentPage I have a ListView inside a StackLayout inside a ScrollView. The ListView is populated (ItemSource is set) in the ContentPage when OnAppearing gets called and I can see that the list is populated in the emulator. The StackLayouts orientation is Vertical and below the ListView I have a Button.
My problem is that no matter how many elements the ListView has, it gets the height of 53.33. I would like the height of the ListView to match the total height of the items in it. By setting HeightRequest I can set the height of the ListView to anything I want, but since I do not know the height of the items inside the ListView the result is most often that the distance to the button below it is incorrect and therefore looks ugly. I have tried to set VerticalOptions on both the ListView and the StackLayout to Startand other settings, but this does not change the height from 53.33 (and if I try to combine using HeightRequest and Start it turns out that HeightRequest wins out).
How can I solve this?
(please excuse the cross posting from Xamarin forum)
With the new BindableLayout feature in Xamarin Forms 3.5 you can easily use the ItemsSource on StackPanel.
So, basically you can write something like this:
<StackLayout BindableLayout.ItemsSource="{Binding list}">
<BindableLayout.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
You can read more about it here: https://blog.xamarin.com/xamarin-forms-3-5-a-little-bindable-love/
The solution in my case was to put the ListView inside a StackLayout and then put that StackLayout inside the main StackLayout. Then I could set the VerticalOptions = LayoutOptions.FillAndExpand on the inner StackLayout (the one containing the ListView) with the result that the ListView got the space it needed (which of course varies depending on the data).
Here is the main code:
listView.ItemsSource = alternativeCells;
listView.ItemSelected += ListViewOnItemSelected;
var listStackLayout = new StackLayout
{
VerticalOptions = LayoutOptions.FillAndExpand,
Orientation = StackOrientation.Vertical
};
listStackLayout.Children.Add(listView);
_stackLayout.Children.Add(listStackLayout);
As you see, I added a new StackLayout with the only purpose of putting the ListView inside it. Then I put that listStackLayout inside the main _stackLayout.
See the post on this Xamarin forum post for more information
I ran into the same problem, and for me this worked like a charm:
listView.HasUnevenRows = true;
(http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/listview/#Display_Rows_with_Variable_Heights)
I had the same problem, and this was the only thing I did that solved for me (in XAML):
<StackLayout Orientation="Vertical"
VerticalOptions="Fill"
HorizontalOptions="StartAndExpand">
<ListView VerticalOptions="FillAndExpand"
RowHeight="<some row height>">
</ListView>
</StackLayout>
Hope it works!
Below code worked for me,
protected override void OnAppearing()
{
base.OnAppearing();
listViewOrderCloths.HeightRequest = model.ListOrderedCloths.Count*100)/2 ;
}
I had a similar struggle, with a slightly different solution. First, setting a RowHeight on the ListView seemed to be pivotal. Second, I was running into a binding + timing issue. If the ListView was displayed and had no contents, it was set to a default height (showing the empty space). If I moved away from this page and came back, the size was fine.
So my approach was to bind the ListView's visibility to the presence (or lack of) something being bound to. Then when data came back, the ListView became visible and had the proper size.
<ListView x:Name="lvSettlements" ItemsSource="{Binding RecentSettlements}" VerticalOptions="FillAndExpand" RowHeight="25" IsVisible="{Binding RecentSettlements, Converter={StaticResource nullConverter}}">
...SNIP...
</ListView>
On Android, my table created in code was leaving gaps above and below it.
This fixed it...
HeightRequest="1000000"
I think I have the hackiest solution.
The accepted answer wasn't applicable to my situation, where my ListView might be longer then the length of the display, hence it needs be placed within a ScrollView, which brings back the empty space.
They way I solved this, was to have top level StackLayout and then place the ListView in an immediate ScrollView, like the following XAML:
<?xml version="1.0" encoding="utf-8" ?>
<local:ContentPage>
<StackLayout x:Name="entirePage">
<ScrollView VerticalOptions="FillAndExpand"
Orientation="Vertical">
<ListView x:Name="listView" ItemsSource="{Binding Items}"
Margin="0">
<!-- ListView Stuff -->
</ListView>
</ScrollView>
</StackLayout><!--entirePage-->
</local:ContentPage >

Resources