Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 58056 articles
Browse latest View live

How can i create event click like a button to grid

$
0
0

I have this grid layout

<ContentPage.Content>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <BoxView Color="Red" Grid.Row="0" Grid.Column="0" />
                        <BoxView Color="Green" Grid.Row="0" Grid.Column="1" />
                        <BoxView Color="Green" Grid.Row="1" Grid.Column="0" />
                        <BoxView Color="Green" Grid.Row="1" Grid.Column="1" />

                        <BoxView Color="Green" Grid.Row="2" Grid.Column="0" />
                        <BoxView Color="Green" Grid.Row="2" Grid.Column="1" />
                        <BoxView Color="Yellow" Grid.Row="3" Grid.Column="0" />

                        <Label Text="Desvio" Grid.Row="0" Grid.Column="0" TextColor="White" FontAttributes="Bold"/>
                        <Label Text="Faturamento" Grid.Row="0" Grid.Column="0" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ContentPage.Content>

each row/colum i need to create an event and each event will go call a rest service and to do something. How can i declare this events for each row/column?

Off topic - > how can i use RowSpan to design my layout in the example above?


Assertion error for ViewCell.Tapped

$
0
0

I'm getting a weird error for what feel like should be something straightforward. I have a ListView with a DataTemplate shown below. For some reason when I run this, and tap on a cell, it closes immediately with

Assertion at [Long Path]/xamarin-android/external/mono/mono/metadata/marshal.c:7928, condition `mono_method_signature (method)->pinvoke' not met

in the Output.
The XAML in question:

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell x:Name="_vcellBlock"
                              Tapped="_vcellBlock_Clicked">
                        <StackLayout x:Name="_stkCellBlock"
                                     Orientation="Horizontal">

                            <StackLayout Orientation="Vertical"
                                         HorizontalOptions="StartAndExpand">
                                <Label Text="{Binding Name}"
                                       FontSize="Medium"/>
                                <Label Text="{Binding Description}"/>
                            </StackLayout>

                            <Frame
                                WidthRequest="75"
                                Padding="0"
                                HorizontalOptions="End">
                                <Label x:Name="_lblListQty"
                                       Text="{Binding QuantityToString}"
                                       HorizontalOptions="Center"
                                       VerticalOptions="Center"
                                       FontSize="Large"
                                   />
                            </Frame>

                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

_vcellBlock_Clicked is defined, but it doesn't seem to matter since break points put on the function are never hit. The assertion is killing it before the event handler ever gets called.

Edit: Other event handlers works fine (like those in the toolbar).

Additional edit: Swapping the event out for an ItemTappedEvent attached to the ListView "solves" the problem in the sense that it no longer fails the assertion. I'd still like to know why though.

Themes leaking WeakReferences (I think)

$
0
0

I've been spending a lot of time trying to track down memory leaks in our Xamarin.Forms app on Android. After a lot of blind alleys and false dawns, I think I may have come across something which is causing the problem.

Using Xamarin Profiler, I can see that as soon as I create a Style and apply it to a control (or in fact just an implicit style), we get Multiple WeakReferences remaining 'Live' - i.e. not garbage collected.

Note that I assume that the objects to which they refer have been GC'd (because the reference to the object is weak), but the WeakReferences themselves are remaining.

Now of course WeakReferences are small I know - but when you have hundreds created on every iteration of a page push/pop, then the memory adds up and we have a significant leak.

Here are the details.
Using Xamarin.Forms 2.3.4.270 (we haven't upgraded because we want to keep with known issues!)
Running on Android - physical device.

App.xaml:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ProfiledFormsApp2;assembly=ProfiledFormsApp2" 
     x:Class="ProfiledFormsApp2.App">
    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="Label">
                <Setter Property="FontSize" Value="Large" />
                <Setter Property="TextColor" Value="Blue" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Page XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage Title="Plain Page" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="ProfiledFormsApp2.PlainPage">
    <ContentPage.Content>
        <StackLayout>
            <StackLayout Orientation="Horizontal">
                <Label Text="Core Navigation"/>
                <Label Text="Number of items:" />
                <Label Text="{Binding ItemsCount}" />
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

When I navigate to the above page and back 3 times, we have the following WeakReference (and related) classes created - the screenshot below is from a Profiler snapshot.

Note we have 55 WeakReferences. Drilling into these shows:

What is interesting is that these WeakReferences seem to be created as part of Behavior and Trigger attaching. Looking at the call tree for the top one gives:

So it appears that the WeakReference was created as part of setting a BindableObject's value and the subsequent setting of the Style.

And it also appears that the WeakReference is still in memory and being referenced by something - the Behavior collection?

Using Profiler, I'm can see that we don't have Labels remaining un GC'd. It seems to be something in the Theme/Behavior/Trigger processing.

I haven't looked at the Xamarin.Forms code on GitHub yet - that might have to be my next action.

Has anyone observed this or got a solution?

@NMackay, @JohnHardman You may be interested in this as this could be the underlying cause of the memory leak I thought I observed some time ago and mentioned in a post here.

How can i load two or more image in the grid

$
0
0

I have this layout

<ContentPage.Content>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>



            <BoxView BackgroundColor="Red" Grid.Row="0" Grid.Column="0"  />

            <Label Text="(-1M)" Grid.Row="0" Grid.Column="0" TextColor="White" FontAttributes="Bold"/>
            <Label Text="Desvio de Faturamento" Grid.Row="0" Grid.Column="0" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>

            <BoxView BackgroundColor="Green" Grid.Row="0" Grid.Column="1" />

            <Label Text="80%" Grid.Row="0" Grid.Column="1" TextColor="White" FontAttributes="Bold"/>
            <Label Text="Ocupação" Grid.Row="0" Grid.Column="1" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>


            <BoxView BackgroundColor="Green" Grid.Row="1" Grid.Column="0" />

            <Label Text="75" Grid.Row="1" Grid.Column="0" TextColor="White" FontAttributes="Bold"/>
            <Label Text="Tickets Cancelados" Grid.Row="1" Grid.Column="0" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>

            <BoxView BackgroundColor="Green" Grid.Row="1" Grid.Column="1" />

            <Label Text="956" Grid.Row="1" Grid.Column="1" TextColor="White" FontAttributes="Bold"/>
            <Label Text="Pendências" Grid.Row="1" Grid.Column="1" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>


            <BoxView BackgroundColor="Green" Grid.Row="2" Grid.Column="0" />

            <Label Text="56" Grid.Row="2" Grid.Column="0" TextColor="White" FontAttributes="Bold"/>
            <Label Text="Limpeza de Pátio" Grid.Row="2" Grid.Column="0" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>


            <BoxView BackgroundColor="Yellow" Grid.Row="2" Grid.Column="1" />

            <Label Text="(-15)/30" Grid.Row="2" Grid.Column="1" TextColor="Black" FontAttributes="Bold"/>
            <Label Text="Check List" Grid.Row="2" Grid.Column="1" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="Black" FontAttributes="Bold"/>


            <BoxView BackgroundColor="Green" Grid.Row="3" Grid.Column="0" />

            <Label Text="37%" Grid.Row="3" Grid.Column="0" TextColor="White" FontAttributes="Bold"/>
            <Label Text="Prestação de Contas" Grid.Row="3" Grid.Column="0" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>

            <StackLayout Spacing="10" Padding="10" VerticalOptions="Center">

                <Image Source="{local:ImageResource My_namespace.Images.ico-cobranca-mensalista.png}" Grid.Row="0" Grid.Column="0" >
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnTapGestureReconizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer>
                    </Image.GestureRecognizers>
                </Image>

            </StackLayout>

            <StackLayout Spacing="10" Padding="10" VerticalOptions="Center">
                <Image Source="{local:ImageResource My_namespace.Images.ico-contrato.png}" Grid.Row="0" Grid.Column="1" >
                    <Image.GestureRecognizers>
                        <!--<TapGestureRecognizer Tapped="OnTapGestureReconizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer>-->
                    </Image.GestureRecognizers>
                </Image>

            </StackLayout>

        </Grid>
    </ContentPage.Content>

the first image is loaded correctly, but others images don't load. Only the first image is shown. I did many attempts and i didn't get success.

How do i bind a property text of the label

$
0
0

I have this layout

<Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <BoxView Color="Red" Grid.Row="0" Grid.Column="0" />
                        <BoxView Color="Green" Grid.Row="0" Grid.Column="1" />
                        <BoxView Color="Green" Grid.Row="1" Grid.Column="0" />
                        <BoxView Color="Green" Grid.Row="1" Grid.Column="1" />

                        <BoxView Color="Green" Grid.Row="2" Grid.Column="0" />
                        <BoxView Color="Green" Grid.Row="2" Grid.Column="1" />
                        <BoxView Color="Yellow" Grid.Row="3" Grid.Column="0" />

            <Image Source="{local:ImageResource TesteAutenticacaoForms.Images.ico-cobranca-mensalista.png}" Grid.Row="0" Grid.Column="0" >
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnTapGestureReconizerTapped" NumberOfTapsRequired="1"></TapGestureRecognizer>
                    </Image.GestureRecognizers>
                     </Image>


                        <Label Text="Test1" Grid.Row="0" Grid.Column="0" TextColor="White" FontAttributes="Bold"/>
                        <Label Text="Test2" Grid.Row="0" Grid.Column="0" VerticalOptions="EndAndExpand" HorizontalOptions="Center" TextColor="White" FontAttributes="Bold"/>
                    </Grid>

and i have this in my .cs

private doubl teste;
public double Teste
{
  get
      {return this.Teste = teste;}
  private set
      {this Teste = value}
}

void OnTapGestureTapped(object sender, EventsAgrs e)
{
    Class_A class_a = new Class_A();
    class_a = MethodCallingService(parameter1, parameter2); ==> this ok
    foreach(var item in class_a)
    {
        teste = item.Valor;
    }
}

public class Class_A : List<Class_B>
{}

public class Class_B
{
    public string Nome { get; set; }
    public double Valor { get; set; }
}

i need to set text property for label. How? I tried this way and isn't work. Text is missed.

<Label Text="{Binding Teste}".... />

Method repeatedly called -- messages to blame?

$
0
0

The client did not want to use an MVVM frameworks so much of my navigation from ViewModel classes is by way of messaging (as is my display of alert boxes) Mostly this works great, however, I do have a problem. When I show an alert, the first time it shows once, but the second time it shows 3 times, and then 8 and then 14. Tracing, I see that all the methods are being called again and again, which is firing off the message again and again.

Is this a known problem? Any suggestions on how to stop it?

Solve the msg Xamarin.Forms.Xaml.XamlParseException:

$
0
0

please help me
When executed, the error message appears
Xamarin.Forms.Xaml.XamlParseException:
vs2017 --- xamarin.forms
xamarin.android
Thank

Cannot debug on android phone

$
0
0

Until a recent update of Xamarin, we have not had any trouble debugging our android app on our Samsung A300FU test device, but now it will not work.

We have tried deleting Mono Shared Runtime & Xamarin.Android APIs from the phone to no avail. We've also tried deleting the bin & obj folders, rebuilding the solution and restarting the computer.

It debugs fine on an emulator, a Samsung J1, and on a Samsung A300Y that we got a lend of.

We've tried disabling Shared Runtime, but no go.

What's really strange is that when we try a different project (e.g. Xamarin Phoneword example), we can debug on our A300FU no problem.

Our project and our test device therefore seem to have fallen out with each other, as all other combinations work no problem.

Here is a screenshot of our Android Options:

Here is a screenshot of our visual studio setup

Anyone got any ideas on what else we can try?


Returning to a Xamarin.Forms View from Platform-Specific PageRenderer

$
0
0

Hi all,

I'm currently exploring using ARKit (iOS) and ARCore (Android) in a Xamarin.Forms project. Since Augmented Reality is platform-dependent and doesn't appear to be exposed in the Forms API yet (unless I'm mistaken), I've opted to implement a platform-specific page renderer for the page I want to leverage AR functionality. Using PageRenderers, I am able to easily present the platform-specific view. However, after finishing platform-dependent work on this new view, I would like a button on screen to return to a new view that is shared by both platforms.

i.e - FormsPage1 > FormsPage2 > PlatformPage > FormsPage3

[assembly:ExportRenderer(typeof(ARSandbox.Views.ARSandboxPage), typeof(ARSandbox.iOS.ARSandboxPageRenderer))]
namespace ARSandbox.iOS
{

    public class ARSandboxPageRenderer : PageRenderer, IARSCNViewDelegate
    {

        /* Lots of neat AR Code for iOS */

        FinishedButton.TouchUpInside += (sender, e) =>
        {
            // TODO: return to a new Xamarin.Forms page
        };

Whats the best way to achieve this? I am using Prism.Forms and an MVVM pattern if it helps

Basic Command Binding not working with .NET Standard

$
0
0
  • Create a new Master Detail Project template then replace About pagecommand code with basic Debug.WriteLine("Hello Command")
  • Deploy to android (API 24)
  • goto about page and click button
  • command will not fire

This is a general issue i have encountered, this is just the easiest way to reproduce, without custom code snippets.

VS 15.5.4
XF 2.5.0.122203
Android Compile with Oreo (Min target API 21)

NB: This event will fire when deployed to UWP

Receive event when context menu appears?

$
0
0

It is easy to show a context menu after a long press on an item in a ListView.

However, imagine a scenario where we have items A, B, C and D in our ListView and item C happens to be the selected item. The item has a highlight colour.

If we long press on, say, item A, the context menu appears, but item C is still highlighted in the ListView.

Has anybody managed to resolve this anomaly?

I would like to have an event that is fired when the context menu appears. That way, I could manually select the item that was long pressed. It would appear clean to the user.

Thank you for any suggestions or ideas on this issue.

Xamarin.Auth, version 1.5.0, error when linking assemblies is enabled, on android (RELEASE)

$
0
0

I am getting the error, in release:

error XA2006: Could not resolve reference to 'System.Void Android.Support.CustomTabs.CustomTabsIntent::(Android.Content.Context,Android.Net.Uri)' (defined in assembly 'Xamarin.Auth, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.Android.Support.CustomTabs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Support.CustomTabs.CustomTabsIntent::LaunchUrl(Android.Content.Context,Android.Net.Uri)

I am using Xamarin.Forms version 2.3.3.193 and CustomTabs vercion 23.3.0

This only happens when I linking the assemblies and on release mode. In debug its working properly!

Maybe Xamarin.Auth bug? or maybe I am doing something wrong?

No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp users may not

$
0
0

Hi,
I am struggling with the following error when i run the xamarin forms in the android environment.

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Warning: 1. No -tsa or -tsacert is provided and this jar is not timestamped Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2047-04-07) or after any future revocation date. (C2C.Droid)

Can any one please help me out this. My iOS project is working fine and android deployment and build was successful my android white screen and suddenly app got stopped

Given Key Not Present in Dictionary Xamarin Forms

$
0
0

I Have a Login ViewModel something like this below

public class LoginViewModel : ViewModelBase
    {

        private readonly IAuthenticationService _authenticationService;

        public LoginViewModel(IAuthenticationService authenticationService)
        {
            _authenticationService = authenticationService;
        }
  } 

And i'm Binding like this in XAML

<ContentPage.BindingContext>
    <viewModels:LoginViewModel />
</ContentPage.BindingContext>

When i Compile i'm getting "Given Key Not Present in Dictionary"

But when i add an Empty Constructor to My ViewModel like this

      public LoginViewModel ()
            {

            }

It working fine ,so is there any workaround for this other than instantiating from Code behind of my ViewPage ?

Text Missing from Page when shown with PushAsync but visible when shown with PushModalAsync

$
0
0

Has anyone come across this issue with Xamarin Forms (2.5.0.122203) where Labels and other text don't show on a child page of a NavigationPage when it's invoked via Navigation.PushAsync but it works fine when invoked via Navigation.PushModalAsync?

I have a video of the issue in action here youtu.be / c24s76nIp1s
(Sorry, had to space it becuase I need to be around for a little while longer!!)

I have tried downgrading Xamarin Forms to 2.4 but the issue persists!


Change DatePicker minimum width 296 to lesser width.

$
0
0

The DatePicker does not resize when width is smaller than 296. It will be cutoff. What is the possible workaround to correct it?

How i can reduce size or stream of image in xamarin forms?

$
0
0

var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
{
PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium
});

    if (file == null)
        return;


    AppApplication.Instance().NewImage = file.GetStream();

    ProfileIcon.Source = ImageSource.FromStream(() =>
    {
        var stream = file.GetStream();
        file.Dispose();
        return stream;
    });

I am trying to reduce size of image which i am selecting from gallery using Plugin.media
How i can reduce size or stream of image in xamarin forms?

How to show Animation in Page Transitions ?

$
0
0

Hi All,

I'm building a XForms app where I'm using Tabbed Page control.
But while Navigating to another page the transition of the space occupied by tabbed page is observable quite clearly which actually looks kind of odd.
So what I was thinking is to implement some Animation kind of thing which will hide this transition of the tabbed page space.

What I need is to show some kind of Animation while transition(navigation) happens from the Tabbed page to Another & vice-versa.
Any help would be appreciated.

Thanks,
Priyabrata

Microsoft azure login page

$
0
0

Is there any way to customize the azure AD login page with company branding.

Master Detail Page Back Button

$
0
0

At first, I made my project using this site
And i can navigate ohter pages through master(hamburger menu)

This is my question.
If i tapped a row of datagrid at ClientPage, it will navigate to ClientDetailPage.
And i can return ClientPage by clicked Navigation Back Button, But!! Hambuger menu icon is disappeared...

//MainPage.xaml
public MainPage()
{
InitializeComponent();
IsPresented = false;
menuList = new List();

            var page1 = new MasterPageItem() { Title = "Client Management", Icon = "ic_import_contacts_black.png", TargetType = typeof(CleintManagementView) };
            var page2 = new MasterPageItem() { Title = "WOD Management", Icon = "", TargetType = typeof(WODManagementView) };
            var page3 = new MasterPageItem() { Title = "Statics", Icon = "", TargetType = typeof(Statics) };

            menuList.Add(page1);
            menuList.Add(page2);
            menuList.Add(page3);

            MenuList.ItemsSource = menuList;
            Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(CleintManagementView)));
}
        #region MasterDetail MenuList Selected
        private void MenuList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item = (MasterPageItem)e.SelectedItem;
            Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
           IsPresented = false;
        }

//ClientPage
private void dataGrid_GridDoubleTapped(object sender, Syncfusion.SfDataGrid.XForms.GridDoubleTappedEventsArgs e)
{
var masterDetail = App.Current.MainPage as MasterDetailPage;
var nav = new NavigationPage();

            var nextPage = new ClientManagementDetailView();
            var selected = e.RowData as People;
            nextPage.BindingContext = selected;
            nextPage.PassContext();
            masterDetail.Detail.Navigation.PushAsync(nextPage);
        }

ClientPage

ClientPage->Double Tapped->ClientDetailPage

Hamburger menu is disappeared..

Viewing all 58056 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>