I use the below code to show image on a from.
<ContentPage>
<ContentPage.Content>
<Grid>
// Row definitions here
// Column definitions here
<Image
Grid.Column="0"
Grid.Row="0"
x:Name="myStoryPage"
Grid.ColumnSpan="3">
</Image>
<!-- Next, previous buttons here -->
<skiaforms:SKCanvasView x:Name="canvasView"
PaintSurface="canvasView_PaintSurface"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="3"
AbsoluteLayout.LayoutBounds="10, 0, 5, 65"/>
</Grid>
</ContentPage.Content>
</ContentPage>
Now I need to highlight an area in the image using SkiaSharp.
I could do drawing a line under the grid using the SKCanvasView. But I want to draw over the image.
I thought to use use AbsoluteLayout but as my page is a ContentPage, I could not use the AbsoluteLayout outside of the content.
If I could use AbsoluteLayout, I can dynamically position it using C# in code behind.
I have a control in Xamarin Forms where I have a bunch of labels that are visible or invisible based on a few factors.
I want the layout I'm calling the control from to wrap the height based on the labels that are visible. So if the labels are 100dp tall for example (I don't actually know how tall they are) and there are 3 visible, I want the height of the control/layout to be 300dp. Right now the layout is just stretching out to what it would look like if all the labels were visible.
This is my control:
<controls:cardDetail>
<Label Text="hi1" IsVisible="{Binding maybe1}">
<Label Text="hi2" IsVisible="{Binding maybe2}">
<Label Text="hi3" IsVisible="{Binding maybe3}">
<Label Text="hi4" IsVisible="{Binding maybe4}">
<Label Text="hi5" IsVisible="{Binding maybe5}">
<Label Text="hi6" IsVisible="{Binding maybe6}">
</controls:cardDetail>
I call this control from a carousel view inside a stacklayout in another xaml page:
<StackLayout orientation="Horizontal">
<CarouselView x:Name="carView">
<controls:cardDetail/>
</CarouselView>
</StackLayout>
What do I have to do to which page/layout to make this happen? Do I need to use C# or can I just add an attribute in xaml??
Thanks!
I am creating a rounded menu with Xamarin Forms as Below.
The accent color is my Grid. Then I translatex and trnaslatey the buttons.
My issue is that the click button is not raised. I have also tried on the gesture recognizer of my stack panel. Same result.
The part of the code is below:
<Grid BackgroundColor="Accent" Margin="0,0,0,10" VerticalOptions="End" HorizontalOptions="Center">
<StackLayout x:Name="cat" TranslationX="-109" TranslationY="-102"
>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="catBtn_Clicked"/>
</StackLayout.GestureRecognizers>
<Button Clicked="catBtn_Clicked" WidthRequest="60"
HeightRequest="60"
FontSize="35"
CornerRadius="30" HorizontalOptions="Center"
BackgroundColor="{StaticResource RedColor}"
TextColor="White"
Text="{ x:Static local:GrialIconsFont.Calendar }"
FontFamily="{ StaticResource IconsFontFamily }">
</Button>
<Label Text="{extensions:Translate Hello}" HorizontalOptions="Center"/>
</StackLayout>
Make sure that your button is placed inside superView's bounds,
If a button is placed outside superView's bounds, the button will not clickable.
You use TranslationX="-109" and TranslationY="-102" will make the button out of the bounds of StackLayout, so it won't response to the click event. You can add backgroundColor to stacklayout to see its bounds.
I would suggest you to add those buttons or labels directly to Grid and use absolute-layout, relative-layout or other layout to fix their positions.
There are also some examples in Github you can refer, such as CircleButtonMenu, Xamarin.Forms-RadialMenu
good day, I'm having a problem with a scroll view, I have a label in a horizontal scroll view, that label concateno amounts, the problem is when the text no longer fit on the screen, the scroll does not move, and I would like if I enter a new quantity in the label, the scroll scrolls so that the last added quantity can be visible, I hope you can help me
This is my XAML:
<ScrollView x:Name="SV" Orientation="Horizontal" HorizontalScrollBarVisibility="Never" HorizontalOptions="FillAndExpand">
<Label Text="{Binding FullSumList}" TextColor="#000000" FontSize="{extensions:ScalableFont 30}" VerticalOptions="EndAndExpand" HorizontalOptions="EndAndExpand" />
</ScrollView>
I searched, not to find a solution
there if I write a quantity, should the scroll go to the left, so that the new quantity is seen
You can use the ScrollToAsync method.
In your xaml
<ScrollView x:Name="SV" Orientation="Horizontal" HorizontalScrollBarVisibility="Never" HorizontalOptions="FillAndExpand">
<Label x:Name="labelTest" Text="{Binding FullSumList}" TextColor="#000000" FontSize="{extensions:ScalableFont 30}" VerticalOptions="EndAndExpand" HorizontalOptions="EndAndExpand" />
</ScrollView>
In the code-behind
SV.ScrollToAsync(labelTest, ScrollToPosition.End, true);
I have the following simple XAML page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Test.UserGuides.VPN">
<ContentPage.Content>
<ScrollView>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center" Margin="10,10,10,10">
<Label Margin="10,10,10,10" Text="How to connect to VPN." HorizontalOptions="Center" />
<Label Margin="10,10,10,10" Text="If you have a corporate notebook, look for the Cisco AnyConnect application. Either in your start menu, on your desktop, or in your taskbar." />
<Image x:Name="imgVPN1" Margin="10,10,10,10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
<Label Margin="10,10,10,10" Text="Select your region and press the Connect button." />
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
In the constructor, I call a method to load the images:
private void LoadImages()
{
imgVPN1.Aspect = Aspect.AspectFit;
ImageSource imagesrc = ImageSource.FromResource("Test.Files.CiscoAnyConnect.PNG");
imgVPN1.Source = imagesrc;
}
The result looks like this on my (rather large, high DPI) phone:
imgur link 1
Of course, I want the image to automatically expand so it takes up the entire width of the screen. While maintaining the aspect ratio. But how can I achieve this? I've already tried putting the Aspect to "AspectFill", and added
imgVPN1.WidthRequest = Application.Current.MainPage.Width;
To the LoadImages method, but that makes the end result look like this:
imgur link 2
I've been toying around with various HorizontalOptions, VerticalOptions, Aspects, GridView, StackLayouts,... The end result is always either the first or the second screenshot. So how can I achieve what I want here?
Here is what can be done. XML almost didn't change, I just removed image Layout Options
<ContentPage.Content>
<ScrollView>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center" Margin="10,10,10,10">
<Label Margin="10,10,10,10" Text="How to connect to VPN." HorizontalOptions="Center" />
<Label Margin="10,10,10,10" Text="If you have a corporate notebook, look for the Cisco AnyConnect application. Either in your start menu, on your desktop, or in your taskbar." />
<Image x:Name="imgVPN1" Margin="10,10,10,10" />
<Label Margin="10,10,10,10" Text="Select your region and press the Connect button." />
</StackLayout>
</ScrollView>
</ContentPage.Content>
After implementing everything in relative layout which also was not simple (I have the code if anybody needs it let me know) I found easier way. The key point is that image doesn't scale correctly and occupies too much space in height. But we know the size ratio of this image so we can use it. In the code we need to override OnSizeAllocated because in constructor the width is unknown yet. Then it's easy
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
imgVPN1.WidthRequest = width;
imgVPN1.HeightRequest = width / 2.152; //given that image is 411 x 191
}
You could use other width than page with if you want. For example you could use stack layout width to consider margins for more accuracy but this is already tuning. Or you actually could use the image width itself like that
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
double needHeight=imgVPN1.Width / 2.152;
if (imgVPN1.Height != needHeight)
imgVPN1.HeightRequest = needHeight;
}
Here is what you need.
<ContentPage.Content>
<ScrollView>
<StackLayout Margin="20" Spacing="10">
<Label Text="How to connect to VPN." HorizontalOptions="Center" />
<Label Text="If you have a corporate notebook, look for the Cisco AnyConnect application. Either in your start menu, on your desktop, or in your taskbar." />
<Image Source="yourimage.jpg" HorizontalOptions="Fill" />
<Label Text="Select your region and press the Connect button." />
</StackLayout>
</ScrollView>
</ContentPage.Content>