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

Image over grid.row/grid.column doesn't work

$
0
0

I did this:

<Image Source="my_image.png" Grid.Row="0" Grid.Column="0" ></Image>

when i run my app doesn't appear. I'm having many issues with to load image in my App. That image is at root of app(PCL Project). My complete code(xaml)

<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" />

            <Image Source="my_image.png" Grid.Row="0" Grid.Column="0" ></Image>

                        <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>

Cannot find app in Android emulator (Visual Studio 2017)

$
0
0

I have started a basic tutorial on how to develop a cross platform app via azure using xamarin.forms. A few days ago, I was able to run the Droid version of the project (via emulator) and found the app there. As of a few days ago, the app is missing when I launch the android emulator. I don't know where to start to resolve this - any help would be appreciated.

I tried updating the packages that the solution uses which may have caused the problem. I had them re-installed to no avail.

Load Custom Render before get current position

$
0
0

i am getting one issue in my app.i am trying to retrieve my current position(Using Mvvm) and pass it to my custom renderer but when try to call below code

if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { CustomPinResponse objresponse = new CustomPinResponse(); var pos = await locator.GetPositionAsync(TimeSpan.FromSeconds(5), null); if (pos != null) { double lat = pos.Latitude; double lon = pos.Longitude; objresponse = await App.GoogleApiBALObject.GetPlaceUsingWord(lat, lon, "hospital"); if (objresponse.Success == true) { for (int i = 0; i < objresponse.Data.Count; i++) { ListCustomPins = new ObservableCollection<CustomPin> { objresponse.Data[i] }; } } else await App.dialogManager.ShowMessage(objresponse.ErrorMessage.ToString(), ""); } }

before retrieve my current position my uwp custom renderer call and could not get any data.

my custom renderer is as below

` protected override void OnElementChanged(ElementChangedEventArgs

e)
{
base.OnElementChanged(e);

        if (e.OldElement != null)
        {
            nativeMap.MapElementClick -= OnMapElementClick;
            nativeMap.Children.Clear();
            mapOverlay = null;
            nativeMap = null;
        }

        if (e.NewElement != null)
        {

            var formsMap = (ModifyMap)e.NewElement;
            nativeMap = Control as MapControl;
            customPins = formsMap.Items;

            nativeMap.Children.Clear();
            nativeMap.MapElementClick += OnMapElementClick;

            if (customPins != null)
            {
                foreach (var pin in customPins)
                {
                    var snPosition = new BasicGeoposition { Latitude = pin.Pin.Position.Latitude, Longitude = pin.Pin.Position.Longitude };
                    var snPoint = new Geopoint(snPosition);

                    var mapIcon = new MapIcon();
                    mapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/pin.png"));
                    mapIcon.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
                    mapIcon.Location = snPoint;
                    mapIcon.NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0);
                    nativeMap.MapElements.Add(mapIcon);
                }


            }
        }
    }`

Please help me i tried to search on google but not found any proper solution.

Update single sqlite value from ListView contain switch control on value TRU/Fals changed (Toggled)

$
0
0

I need instant and single value true/false to be reflected to my sqlite when I changed the switch value.

I have ListView binding it with ViewModel . I'm new at Xarmarin maybe i missing something.

         <ListView 
                        ItemsSource="{Binding Items}"
                         HasUnevenRows="true"
                         RefreshCommand="{Binding LoadItemsCommand}"
                         IsPullToRefreshEnabled="true"
                         IsRefreshing="{Binding IsBusy, Mode=OneWay}"
                         CachingStrategy="RecycleElement"
                        >
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout Padding="10">
                                        <StackLayout Orientation="Horizontal">
                                            <Label Text="Is Checked?" />
                                            <Switch   IsToggled="{Binding IsChecked}"  />
                                        </StackLayout>
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

               public partial class Details : ContentPage
                {

                    MyViewModel viewModel;

                    public ViewDayDetails()
                    {
                        InitializeComponent();
                        BindingContext = viewModel = new MyViewModel();
                    }

                    protected override void OnAppearing()
                    {
                        base.OnAppearing();
                        if (viewModel == null || viewModel.Items == null || viewModel.Items.Count == 0)
                            viewModel.LoadItemsCommand.Execute(null);
                    }
                }

        public class MyViewModel : BaseViewModel
            {
                public ObservableCollection<MyModel> Items { get; set; }
                public Command LoadItemsCommand { get; set; }
                public MyViewModel ()
                {

                    Items = new ObservableCollection<MyModel>();
                    LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
                }

                    async Task ExecuteLoadItemsCommand()
                    {
                        if (IsBusy)
                            return;
                        IsBusy = true;
                        try
                        {
                            Items.Clear();
                            var items = await App.Database.GetList();
                            foreach (var item in items)
                            {
                                Items.Add(item);
                            }
                            IsBusy = false;
                        }
                        catch (Exception ex)
                        {
                           Debug.WriteLine(ex);
                        }
                        finally
                        {
                            IsBusy = false;
                        }
                    }
                }

How to prevent overlapping navigation in NavigationPage?

$
0
0

I am currently trying to fix an annoying problem in my Xamarin Forms app (iOS and Android).

Assume a NavigationPage that currently has two pages on the stack:

Page2 (topmost, currently displayed)
Page1

Page2 has a Button "Go to Page3", that binds to a Command which in turn executes the following method:

Task Navigate()
{
    return navigationPage.PushAsync(new Page3(), true);
}

Now what I do is the following:
I tap the "< BACK" button in the navigation bar, and then immediately tap "Go to Page3" before Page2 has a chance to disappear.

This causes Page2 to animate away and Page1 to appear. Then as soon as Page1 has appeared, the app navigates to Page3, leading to the following navigation stack:

Page3 (topmost, currently displayed)
Page1

This is more or less correct from the point of view of the NavigationPage I suppose, but I do not want my app to be able to get into this state.
I would be able to prevent this if there was a way to detect back navigation as soon as it starts, but I can't see how to detect that.

How do you solve this issue?

I can't install version 2.5.0.122203

$
0
0

I get errors that undetected packages Xamarin.Android.Support.v7... 25.4.0.2. But I use Xamarin.Android.Support... 26.1.0.1 and target Android version 8.0.
Any help.

Firebase or Insight Tutorial

$
0
0

I can't find any up to date tutorials on how to implement either Firebase or Insight for Xamarin.Forms on Visual Studio. They are all discussing Android Studio to set it up for Android for example (using gradle etc.. no idea what that is). And it seems Insight has become HockeySDK now? I dont know.

I want some crash reporting for my app before I launch it. But Xamarin does not make anything easy or self-explanatory. Everything is such a hazzle with poor to no decent documentation. So please if anybody have added firebase or insight for crash reporting. Please send me the URL to the tutorial you used, for setting it up on Visual Studio. I'm currently stuck...

Splash Screen - MVVM

$
0
0

I'm starting to learn Xamarin, I created a project in MVVM and Prism. I would like to include a Splash Screen screen, but I have already seen several examples and none works, when it works it does not leave the screen. Does anyone have a simple example? Thank you.


Does XAMLC compile DataTemplates?

$
0
0

So I understand how XAMLC works and that it compiles the Xaml which means it has to do less processing at Runtime.

But does it also compile DataTemplates as these are Created at runtime?

Is it better to use a DataTemplate or a ContentView when talking about XAMLC or do they both work in the same way?

Database alternative to store/query high dynamic data structure (JSON or JSON-like)

$
0
0

Hello.

I'm starting the development of a new Xamarin.Forms app that should build dynamic forms with multiple custom input types, configured in a web application and consumed by the app using a REST service (A Google Forms-like app). Considering this requirement the data produced by the user inputs will be very dynamic, depending on the form configuration. The app should be full functional when offline too. For example, a form can have the following configuration structure:

Form 1:

Age : Integer input
Name : Text input
Active : Boolean input
Address : Group {
     Street : Text input
     Number : Integer input
}

An input produced by a given user considering the above "Form 1" configuration can be something like:

{
    Age : 28,
    Name : "Jon",
    Active : true,
    Address : {
        Street : "Main street",
        Number : 100
    }
}

As you can see the result of an user input is a JSON object. Currently I'm looking for an storage solution with the following requirements:

  • Should allow the storage of dynamic data structures (like the above data structure)
  • Should allow query by user inputs. The query engine should support queries like "Return records where Anddress.Street starts with 'Main'". Remember that the data structure is not know. The inputs are schema-less.
  • Compatible with Xamarin.Forms applications (using a .NET Standard 2.0 project for code sharing)

I have took a look in a lot of alternatives, like CouchDB, Siaqodb, Realm, etc. but none of the alternatives has fit my requirements. I think that I'm looking for a kind of "MongoDB lite" to work with Xamarin.Forms. Does anyone know something like this?

Can anyone suggest me an alternative that fits these requirements or provide any guidance about how to achieve my goal?

ListView Method Alike 'ItemSelected', 'GroupSelected'

$
0
0

I'd like to remove items from the ListView's ItemSource collection. It's easy to get a reference to the currently selected item. However I do not have a reference to the group containing the item. I can traverse the collection to find the group containing the item, then remove it from the group. I have a feeling there could be a better way to accomplish this. Are there any Xamarin offered solution to find the currently selected group? Or any 'better' solution than traversing the whole collection?

Block picker content editing

$
0
0

How to block editing of picker component text?
If you copy and paste a text within it it accepts.

My picker is a custom render.

Xamarin.Forms Maps UWP, IOS, details of phone and more

$
0
0

Okay, i'm doing my engineering degree project and i need to do few small Xamarin.Forms programs to compare them with Cordova and others.
1st i have few problems with Xamarin.Forms.Map which i used like in Xamarin.Forms.Map tutorial
1. On iOS version i have no "localization" button even if i have isShowingUser as true. Is this some bug or i do something wrong ?
2. I added some "basic" button and it's transparent on iOS version while on Android it's grey, is there possibility to make it grey on iOS too?
3. Is there possibility of gaining details of phone (more than model,ID,idiom and version of system) through shared part of program ?

I hope i didn't wrote anything stupid. Thx for any help.

UWP App - Immediate Crashes

$
0
0

Hello,

We have a Xamarin.Forms app targeting iOS, Android, and UWP. We're using a PCL for our common Xamarin.Forms code. We're on an older version of the Xamarin.Forms library (version 2.3.4.231).

I recently tried updating the Nuget packages for all projects in our solution to the latest Xamarin.Forms library (version 2.5.0.122203). Everything works fine in iOS and Android. However, when I attempt to run a UWP Debug x86 build on the local machine, the app crashes immediately. I have attached what I see from the event log.

Here is the project.json file (before updating packages):
{
"dependencies": {
"Acr.UserDialogs": "6.3.10",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"modernhttpclient": "2.4.2",
"PCLCrypto": "2.0.147",
"Plugin.Permissions": "1.2.1",
"Splat": "1.6.2",
"Xam.Plugin.Connectivity": "2.2.12",
"Xam.Plugin.Geolocator": "3.0.4",
"Xam.Plugin.Media": "2.6.1",
"Xamarin.Forms": "2.3.4.231",
"Xamarin.Insights": "1.12.3"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}

And after:
{
"dependencies": {
"Acr.UserDialogs": "6.3.10",
"Microsoft.NETCore.UniversalWindowsPlatform": "6.0.6",
"modernhttpclient": "2.4.2",
"PCLCrypto": "2.0.147",
"Plugin.Permissions": "2.2.1",
"Splat": "1.6.2",
"Xam.Plugin.Connectivity": "3.0.3",
"Xam.Plugin.Geolocator": "4.2.0",
"Xam.Plugin.Media": "3.1.2",
"Xamarin.Forms": "2.5.0.122203",
"Xamarin.Insights": "1.12.3"
},
"frameworks": {
"uap10.0.14393": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}

If I change the Xamarin.Forms dependency back to a version 2.3.XXX variant the app will not immediately crash on startup. However, because a later version of Xamarin.Forms is being used by our PCL, the app doesn't work quite right at runtime (e.g. Device.Runtime is Windows instead of UWP). I also tried 2.4.XXX variants of the Xamarin.Forms dependeny in our UWP app - those fail too.

Is this a known issue? Anybody know how to resolve this?

Thanks.

How to bind Button command to ViewModel and IsEnabled to model (bug?)?

$
0
0

I have a listview created with a data template for the group header and for the item. The listview has an ItemsSource "Weeks" in which there is an array with "items" which will be used to populate the items belonging to the group. Every item has a button which is binding to a value in the "item" model. But the button command is binding to the viewmodel. As soon as I do that, things go wrong. If I set "IsEnabled" to false when the listview is loading, it will not disable the button as soon as I have set the command in my viewmodel or model. If I don't assign the command everything works. If I remove the Command from the XAML, all is well.
The command will execute a check if a value is '0' and then will disable the button("IsEnabled=false"), this works all the time, no matter where the Command is binded/set. It is merely the loading. If the button is disabled after pressing the button, the button is scrolled out of view and then back in, the button is enabled again. So it is really connected to loading/showing the button.

I need to bind the Command to the viewmodel as I believe that is the way to do it and I need to know when the button is pressed so the viewmodel can handle some actions and UI updates.

<Button x:Name="minButton" Text="-" Style="{StaticResource borderlessButton}" IsEnabled="{Binding IsMinButtonEnabled}" Command="{Binding Source={x:Reference Name=PredictView}, Path=BindingContext.MinButton}" CommandParameter="{Binding .}" Grid.Column="1"/>

Is there something I'm doing wrong or is this a bug?


Setting binding in code in a custom control

$
0
0

I am trying to make a simple control that combines an entry and a label.
The binding doesn't work, however, and I don't understand why.
Can anyone help clarify?

Here's my control xaml

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Custom.Controls.LabelEntry">

    <ContentView.Content>

        <Grid x:Name="cGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Label x:Name="cLabel"
                   Grid.Column="0"/>

            <Entry x:Name="cEntry"
                   Grid.Column="1"/>

        </Grid>

    </ContentView.Content>

</ContentView>

and my control xaml.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LabelEntry : ContentView
{
    public LabelEntry()
    {
        InitializeComponent();
    }

    #region Binding for LabelText
    public static readonly BindableProperty LabelTextProperty = BindableProperty.Create(
        propertyName: "LabelText",
        returnType: typeof(string),
        declaringType: typeof(LabelEntry),
        defaultValue: "",
        defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: LabelTextPropertyChanged);

    public string LabelText { get; set; }

    private static void LabelTextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (LabelEntry)bindable;
        control.cLabel.Text = newValue?.ToString();
    }
    #endregion

    #region Binding for LabelStyle
    public static readonly BindableProperty LabelStyleProperty = BindableProperty.Create(
        propertyName: "LabelStyle",
        returnType: typeof(Style),
        declaringType: typeof(LabelEntry),
        defaultValue: null,
        defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: LabelStylePropertyChanged);

    public Style LabelStyle { get; set; }

    private static void LabelStylePropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (LabelEntry)bindable;
        control.cLabel.Style = (Style)newValue;
    }
    #endregion

    #region Binding for EntryText
    public static readonly BindableProperty EntryTextProperty = BindableProperty.Create(
        propertyName: "EntryText",
        returnType: typeof(string),
        declaringType: typeof(LabelEntry),
        defaultValue: "",
        defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: EntryTextPropertyChanged
        );

    public string EntryText
    {
        get => (string)GetValue(EntryTextProperty);
        set => SetValue(EntryTextProperty, value);
    }

    private static void EntryTextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (LabelEntry)bindable;
        control.cEntry.Text = newValue?.ToString();
    }
    #endregion

    #region Binding for EntryPlaceholder
    public static readonly BindableProperty EntryPlaceholderProperty = BindableProperty.Create(
        propertyName: "EntryPlaceholder",
        returnType: typeof(string),
        declaringType: typeof(LabelEntry),
        defaultValue: "",
        defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: EntryPlaceholderPropertyChanged);

    public string EntryPlaceholder { get; set; }

    private static void EntryPlaceholderPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (LabelEntry)bindable;
        control.cEntry.Placeholder = newValue?.ToString();
    }
    #endregion

    #region Binding for EntryStyle
    public static readonly BindableProperty EntryStyleProperty = BindableProperty.Create(
        propertyName: "EntryStyle",
        returnType: typeof(Style),
        declaringType: typeof(LabelEntry),
        defaultValue: null,
        defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: EntryStylePropertyChanged);

    public Style EntryStyle { get; set; }

    private static void EntryStylePropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (LabelEntry)bindable;
        control.cEntry.Style = (Style)newValue;
    }
    #endregion

    #region Binding for GridStyle
    public static readonly BindableProperty GridStyleProperty = BindableProperty.Create(
        propertyName: "GridStyle",
        returnType: typeof(Style),
        declaringType: typeof(LabelEntry),
        defaultValue: null,
        defaultBindingMode: BindingMode.TwoWay,
        propertyChanged: GridStylePropertyChanged);

    public Style GridStyle { get; set; }

    private static void GridStylePropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = (LabelEntry)bindable;
        control.cGrid.Style = (Style)newValue;
    }
    #endregion
}

and how I use the control

<custom:LabelEntry Style="{StaticResource SimpleLabelEntry}"
                       LabelText="Test Label"
                       EntryPlaceholder="Test Placeholder"
                       EntryText="{Binding TestData}"/>

where TestData is a property that implements INotifyPropertyChanged in my view model

Is there any alternative of Volley used in android to call REST services for Xamarin Forms?

$
0
0

I am looking for any alternative of volley in xamarin forms to communicate with REST services. I am currently using HttpClient to communicate with REST services. But now i am looking for some alternative which gives me advantages of volley. I searched but nothing found . If anybody knows please comment.

How to move a button when it is clicked

$
0
0

I have two frames and a button which I have set up in an absolute layout in XAML. The second frame has the IsVisible property set to false. When the button is clicked I would like to move the button down to a new position and set the IsVisible property on the second frame to true. I have tried to use ViewExtensions.TranslateTo() and ViewExtensions.LayoutTo() but it seems to make my button disappear. Anyone know how to move the button to the new position on click?

Custom Editor inside a listview disables on show

$
0
0

Hi,

I have a custom listview using custom viewcells having radio buttons and editor control inside it. On tapping the radio buttons the comment box visibility is toggled (show/hide).
On loading the listview for the first time the editor control visibility is by default hidden. Once the radio buttons are tapped, the editor is displayed. The issue here is that the editor disables when it is shown and no keyboard pops up on tapping it.

It works perfectly fine on Android and IOS versions till 10.3

I am facing this issue with all IOS devices having version 11 and above.

Xamarin Forms v2.5.0.91635

Please help.

Thanks,

Android Toolbar height in Xamarin.Forms

$
0
0

Does anyone know how to get the toolbar height in Xamarin.Forms on Android?

Viewing all 58056 articles
Browse latest View live


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