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

Xamarin.Forms v.2.5 compatibility with older Xamarin.iOs

$
0
0

Hi everyone,
I'm updating nuget packages on my Xamarin.Forms app.
I had no problem updating to 2.5 for my Android project but I had some compilations issues on iOs, as 2.5 seems to be unsupported for my Xamarin.iOs version - 6.3 build 864.
For my Mac Agent I have an old Mac Mini with El Capitan (10.11.6), and that keeps me from updating my XCode any further than 8.0, and it seems like I need newer versions in order to update my Xamarin.iOs - which allows me to update .Forms to 2.5.
Is that correct? I haven't ever seen any of these constraints on Xamarin website, but I really couldn't compile any packages with newer versions. Right now I'm stuck at the later 2.3 ones, I also got some runtime errors and I suspect this is due to the version difference between Xamarin.Forms.Portable and Xamarin.Forms.iOs versions.

Any pointers?
Thanks in advance


Using MessagingCenter to send message from ViewModel to Xaml Code behind

$
0
0

Hi

I need to display some text in a textbox for ongoing debug purposes. In my codebehind for my Xaml page, I have:

protected override void OnAppearing(
{
            base.OnAppearing();
            MessagingCenter.Subscribe<string>(this, "UpdateStatus",(arg) =>
            {
                StatusText.Text += $"\n{DateTime.Now:HH:mm:ss}: {arg}";
            });
}

On my ViewModel, I have:

StatusTextText = new Command(() => { MessagingCenter.Send("UpdateStatus", "Searching For Device"); });

On My XAML, I have:

<Button Margin="0,10,0,0" Text="Find Device" Command="{Binding StatusTextText }" BackgroundColor="{StaticResource Primary}" TextColor="White" />

<Editor x:Name="StatusText" 
                        VerticalOptions="FillAndExpand"
                        Focused="OnStatusTextFocussed"
                        FontSize="Micro"/>

The view displays and the MessagingCenter.Subscribe line is executed without error. When I click the button, I an see in the debugger that the code on the viewmodel runs, calling MessagingCenter.Send, but the message "Searching For Device" never shows up in the StatusText.

I am lead to believe that the Messaging Centre is global, any client to any subscriber. I have simplified it removing the class names to ensure that it is global, but still the message fails to arrive at the other end.

Any Ideas?

Nigel

Google Maps for Xamarin forms iOS & Android.

$
0
0

Hi,

I am new in Xamarin, I need to required Google Maps for Xamarin forms iOS & Android.
Not need to required Xamarin.Forms.Maps

Please help me.

Generic base class for a custom ContentPage

$
0
0

The last Xamarin.Forms release notes had this comment:

  • [XAML] x:TypeArguments now works at root level, fixing generic subclassing from XAML

That sounds like exactly what I'm trying to do, but I'm struggling to come up with the right syntax to make it work.

I have a base class for all of my custom pages:

public class PageBase<TViewModel> : ContentPage
    where TViewModel : ViewModel
{
    public TViewModel ViewModel { get { return BindingContext as TViewModel; } }
}

Then one of my custom pages looks something like this:

public class MyPage : PageBase<MyPageViewModel>
{
    // ...
}

The hard part is figuring out how to write MyPage.xaml. Here is what I have tried:

<?xml version="1.0" encoding="UTF-8"?>
<local:PageBase
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:App.View.Pages;assembly=App"
    x:Class="App.View.Pages.MyPage"
    x:TypeArguments="App.ViewModel.Pages.MyPageViewModel">
    <!-- ... -->
</local:PageBase>

When I build this I get a compile error because the generated MyPage.xaml.g.cs file looks like this:

public partial class MyPage : global::App.View.Pages.PageBase {
    private void InitializeComponent() {
        this.LoadFromXaml(typeof(MyPage));
    }
}

The error is that there is no type specifier for the base class. It should look like this:

public partial class MyPage : global::App.View.Pages.PageBase<global::App.ViewModel.Pages.MyPageViewModel> {
    private void InitializeComponent() {
        this.LoadFromXaml(typeof(MyPage));
    }
}

Based on the line in the release notes I believe this is possible, but I must be missing something. How can I make this do what I want it to do?

Shared HttpClient and simultaneous requests

$
0
0

I'm writing a networking layer in a Xamarin.Forms PCL project. The main class uses HttpClient to execute requests. If the request is successful, a success lambda is executed, and if the request fails a failure lambda is executed.

This is a fire and forget type scenario. I'm calling my networking class from a UI thread, and expecting the real work to be done in the success lambda whenever the request finally completes. That all works great, but I've been noticing a message in the console.

WARNING: An HttpWebRequest was added to the ConnectionGroup queue because the connection limit was reached.

I have been reading that the intended usage of HttpClient is to have 1 instance shared and used everywhere, but it appears that if I fire off 2 simultaneous requests, each using the same HttpClient instance, this message is being generated. Is the advice I'm reading necessarily true for for Mono's HttpClient? should I instead prefer an implementation along the lines of...

using(var client = new HttpClient())
{
}

Here is some pseudo code that will give you the gist of how my program is working

// 1 shared HttpClient does all the hard work
Client client = new Client(new HttpClient());

// Just making one request causes no warning, works just as intended.
public void oneCall() {
    // Fire off a non-blocking networking function
    client.request("GET", "http://example.com",
        success: (data) => { 
            //Do something
        },
        failure: (data) => {
            // Failed
        });
    // Some UI code that gets called without waiting for the request to finish.
}

// Making 2 non-blocking requests in a row causes a WARNING (see above) in the console
public void twoSimultaneousCalls() {
    client.request("GET", "http://example.com",
        success: (data) => { 
            //Do something
        },
        failure: (data) => {
            // Failed
        });
    client.request("GET", "http://example.com/anotherResource",
        success: (data) => { 
            //Do something
        },
        failure: (data) => {
            // Failed
        });
    // Some UI code that gets called without waiting for requests to finish.
}

So is it REALLY true in the Xamarin/mobile world that using a shared HttpClient is recommended? Is it REALLY that thread safe? Should I prefer a "using" approach instead? Are there any MaxConnections or ThreadPool type settings I can adjust to support a number of simultaneous requests?

Some reading I've done

How to Create a Custom Xamarin Forms Template

$
0
0

We are trying to create a Xamarin Forms "boilerplate" for our company's enterprise Xamarin Forms applications. Each application that we have made requires the integration of our company's "common libraries" (security, theme, etc). We simply need to be able to create a new Xamarin Forms app that includes all of these libraries, NuGet packages and common pages/viewmodels/models.

One idea is to create a Visual Studio Template. Not sure if this is the "correct" way to do this because you only have the option of exporting one project in your solution (to a template). We would like to export our App, App.Android, App.iOS & App.UWP projects as a template. Even if we were able to export these projects (combined) as a template, would the GUIDs generated by Xamarin be "re-generated"? Would the App names be populated? Not sure...

Anyways, we have created a "boilerplate" Xamarin Forms app that we would like to export as a Visual Studio template. How do we create Xamarin Forms Visual Studio templates (how do you turn a Xamarin Forms solution into a custom template in the "Cross Platform App (Xamarin)" => "Blank/Master Detail/Our Custom Template" menu)? If there is a different way to accomplish similar ends, then we are happy to explore it!

ListView Show context menu on long press

$
0
0

Is there any support for showing a context menu when you long press a list view item?

Or any support for context menus at all?

Best way to store Chat history from multiple Chat Rooms

$
0
0

So I have chat functionality for my app. Right now It is just one global room, all messages get loaded.
I want to create seperate chat rooms and I want to store the chat history efficiently. If I have thousands or tens of thousands of new messages being sent daily and they are all being stored into one table it seems crazy inefficient to have each user have to search through ALL of those messages every time they open a chat...
I have read about a few technies. The coolest one is having 2 tables.
One that stores the 2 (or more) users IDs and then a count of total messages sent.
The second table has all the messages but is grouped by the 2 User ID combo. And you just find that cell and then read the message data only to do with all the cells of the same name. This is the article that I found that presents that idea. http://qnimate.com/database-design-for-storing-chat-messages/ Someone in the comments said that they achieved the same thing but with just one table, is that better?

But is that the best way? And if it is, any tips on how to pull that off with Azure Mobile App and Xamarin Forms? I think I can figure it out, but pointers are always welcome! :smiley:


How to delete an item from a ListView in MVVM

$
0
0

Hi, I am new to Xamarin, Forms and MVVM, so this might sound a little dumb, but what is the proper way to delete an item from a ListView? I tried to do it with a ContextAction, but I can't figure a way to know in my ViewModel which item to delete from the ObservableCollection. Binding the SelectedItem of the ListView does not help, since a long tap on Android or a swipe on iOS don't select the item. I use Prism with Unity for MVVM, if this is of any importance. Here's my ListView:

<ListView x:Name="List" ItemsSource="{Binding Users}" HasUnevenRows="True">
    <ListView.Behaviors>
        <b:EventToCommandBehavior EventName="ItemTapped" Command="{Binding SelectUserCommand}" EventArgsConverter="{converters:ItemTappedEventArgsConverter}"/>
    </ListView.Behaviors>
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell x:Name="Item">
                <ViewCell.ContextActions>
                    <MenuItem Text="Delete" BindingContext="{Binding Source={x:Reference List}, Path=BindingContext}" Command="{Binding DeleteCommand}" CommandParameter="{Binding .}" IsDestructive="True"/>
                </ViewCell.ContextActions>
                <Grid Padding="10">
                    <Label Style="{DynamicResource ListItemTextStyle}" Grid.ColumnSpan="2" Text="{Binding Name}"/>
                    <Label Style="{DynamicResource ListItemDetailTextStyle}" Grid.Row="1" Text="{Binding Login}"/>
                    <Label Style="{DynamicResource ListItemDetailTextStyle}" Grid.Row="1" Grid.Column="1" Text="{Binding Role}"/>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

And the corresponding ViewModel (I removed some code to save space):

public class MainPageViewModel : BindableBase, INavigatedAware
{
    //services
    INavigationService _navigationService;
    IPageDialogService _dialogService;

    //fields and props
    private ObservableCollection<User> _users;
    public ObservableCollection<User> Users => _users;

    //commands
    private DelegateCommand _deleteCommand;
    public DelegateCommand DeleteCommand => _deleteCommand ?? (_deleteCommand = new DelegateCommand(DeleteUser));

    //methods
    public MainPageViewModel(INavigationService navigationService, IPageDialogService dialogService)
    {
        _navigationService = navigationService;
        _dialogService = dialogService;

        _users = new ObservableCollection<User>() { new User() { Login = "Login", Name = "Name", Role = "Role" } };
    }

    private void DeleteUser() => Debug.WriteLine("This should delete a user");
}

I would appreciate if anyone could explain me how should I implement the deletion of an item using the MVVM pattern. Thanks

Timer in Portable Class Library?

CustomMap System.Reflection.TargetInvocationException

$
0
0

Hello. I had created CustomPin, CustomMap and CustomMapRenderer for doing different marker images for each of pin. I have CustomMap on Detail page of MasterDetailPage.





I have this exception immediately after Launch Screen.

A photo which is taken from iOS camera rotating 90 degree on android

$
0
0

Hello, I have Xamarin.Forms application and using FFIMAGELOADING for photos. Photo which is taken from iphone camera rotation 90 degree to left on android phones. Anyone knows the solution? Someone sent a dependency service code but it didn't work well.

MVVM -Binding Listview from viewmodel

$
0
0

I am stuck with this problem for last two days now. I am trying to bind a listview inside my XAML to data retrieved from an sqllite DB via a viewmodel Here is my code

  <Button Command="{Binding ShowTask}" Text="Show" />

    <ListView ItemsSource="{Binding TaskItems,Mode=TwoWay}"
          CachingStrategy="RecycleElement"
          RowHeight="60">

        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Margin="8">

                        <Label Text="{Binding Tasktext}"
                           FontAttributes="Bold" />

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

    </ListView>

the button above should fire the ShowTask command in the viewmodel the viewmodel code is as below

private ObservableCollection<MyXFApp.Data.Task> _TaskItems;
    public ObservableCollection<MyXFApp.Data.Task> TaskItems
    {
        get
        {
            return _TaskItems;

        }
        set
        {
            _TaskItems = value;
            OnPropertyChanged();
        }
    }

    public AddTaskVM()
    {

                  ShowTask = new Command((q) => this.ShowTaskMethod(q), (q) => this.CanShowTaskMethod(q));
    }


    public bool CanShowTaskMethod(object parameter)
    {
        return  true;
    }
    public void ShowTaskMethod(object parameter)
    {

        taskDB = new TaskDB();
        _TaskItems = new ObservableCollection<MyXFApp.Data.Task>(taskDB.GetStudents());

    }

and this is the code for task class

public class Task
{
    [PrimaryKey, AutoIncrement]
    public int Taskid { get; set; }
    public string Tasktext { get; set; }

 }

the command is firing and data is being retrieved but i dont know why the resultant data is not binding to the listview ,any help will be greatly appreciated

Could not find file obj/iPhoneSimulator\Debug\xxxxxx.exe.manifest

$
0
0

Hi
Today I Installed Xamarin iOS Simulator (for Windows) . When I start debug (Debug - IPhoneSimulator - IPhone 5s iOS 9.3) i get following message now:
Could not find file obj/iPhoneSimulator\Debug\xxxxxx.exe.manifest.

There is no manifest file in the directory. How can i force VS to create one ? When I disable remote Simulator on Windows i get the same error now.

Setup
VS 14.0.25425.01 Update 3
Xamarin 4.1.2.18
Xamarin.IOS 9.8.2.22
Xamarin.Forms 2.3.0.107

Reload the Itemssource of a Picker when opening it

$
0
0

Hello everyone,

I am new to the Xamarin.Forms world and started developing my first test application a week ago (deploying on Android).
Coming from ASP.NET C# it´s really interesting to see how this world works and my current knowledge about it is very basic.

My question:
The goal is to implement a simple Picker control which contains values loaded from an ASMX-Service.
For example the web service returns a list of currently available employees (to call by phone). So the results returned by the ASMX-Service can be different within a short time.
To take it a bit easier in the first step, I don´t call the ASMX-Service but return a random collection generated in the Itemssource property of my Picker.
I am doing this with a ViewModel class which is used in the constructor of my ConentPage. Also the Itemssource property of my Picker gets filled there (random collection).
When I am running the App and the ContentPage gets initialized, the Itemssource property loads correct and by clicking my Picker I can see all items.

My problem is that the Itemssource property doesn´t get reloaded, when I open my Picker again - it always displays the values generated in the initialization of the ContentPage.
As I said, I want to get the items of my Picker by a web service in the next step and the result from its call can always be different.

How can I force the Picker to reload its Itemssource everytime I open it?
There´s no such thing as an event like "OnLoad" where I have the ability to reload the Itemssource and display the new loaded values in the Picker.
I searched for days now but I can´t find anything with a requirement like that (surprisingly).

Hopefully somebody can help me.
Ostgoda


Culture for localization in iOS

$
0
0

Hello, I'm facing with a new problem trying to retrieve the current culture set on the iphone (as language set to main language of OS).

In one iphone 6 with iOS 11.2.1 when the language is set to italian if I retrieve the lang with these instructions:

    var loc = NSLocale.CurrentLocale.LanguageCode;
    var currCulture = CultureInfo.CurrentCulture.ToString();
            var lang = NSLocale.PreferredLanguages[0];

I found that the first 2 instructions return me a wrong code (en), and the only way that I have to understand the real current language is only reading the variable lang.

On another iphone (6s with iOS 10.3.2) all the variables return the correct value (it and it-IT, and the currCulture is the way that I used until some hours ago convinced that it was the right way to do it).

So I'm asking to myself, what is the best way that give me the assurance to obtain the right code?

How can I bind my object's some properties to picker's?

$
0
0

Hi;

I want to know how to bind my object's some properties to picker's or lables?

Thanks in advance.

Example what I want to achieve;

My object;

public class Book
{
public int BookID{get;set;}
public string BookName{get;set;}
public string ISBN{get;set}
public DateTime RegistrationDate{get;set;}
}

My page;

<ScrollView Orientation="Both"> <StackLayout> <StackLayout Orientation="Horizontal"> <Label FontSize="Medium" Text="Book ID:" /> <Label x:Name="BookID" FontSize="Medium" Text="{Binding BookID}"></Label> </StackLayout> <StackLayout Orientation="Horizontal"> <Label FontSize="Medium" Text="Book Name:" /> <Label x:Name="BookName" FontSize="Medium" Text="{Binding BookName}"></Label> </StackLayout> <StackLayout Orientation="Horizontal"> <Label FontSize="Medium" Text="ISBN:" /> <Label x:Name="ISBN" FontSize="Medium" Text="{Binding ISBN}"></Label> </StackLayout> <StackLayout Orientation="Horizontal"> <Label FontSize="Medium" Text="Registration Date:" /> <Picker x:Name="RegistrationDate" SelectedItem="{Binding RegistrationDate, Mode=TwoWay}" WidthRequest="100"></Picker> </StackLayout> </StackLayout> </ScrollView>

Hybrid Webview is not loading google map

$
0
0

In my Xamarin form app I am using HybridWebview. I am trying to load google map in that.But its not loading the map. I have given the following permissions.
ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
ACCESS_LOCATION_EXTRA_COMMANDS
ACCESS_MOCK_LOCATION
ACCESS_NETWORK_STATE
INTERNET
LOCATION_HARDWARE
WRITE_EXTERNAL_STORAGE
But still no luck. javascript is enabled in web view setting. So what else need to be done

Sigh - yet ANOTHER BUG in XF2.5 -> Specified cast is not valid

$
0
0

Moan Start
I guess I should have learnt my lesson and not upgraded all my projects to the latest XF assembly (2.5.0.121934). I like Xamarin but I really dislike the appalling testing (or lack of) on simple things that really should have been tested - I spend so much of my time working around such an unstable environment and writing things multiple ways because of the numerous bugs that are inherent within the API , We are at 2.5 soon to be XF 3.0 and my patience is really running thin to say the least - Xamarin/Microsoft , it would be great if at each new release you could try a little harder NOT TO BREAK what was working in prior versions , is that really too much to ask ??

Moan End

Exception

System.InvalidCastException: Specified cast is not valid.
at (wrapper castclass) System.Object:__castclass_with_cache (object,intptr,intptr)
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in :0
at Xamarin.Forms.Platform.iOS.RendererPool.UpdateRenderers (Xamarin.Forms.Element newElement) [0x0008c] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\RendererPool.cs:157
at Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement (Xamarin.Forms.VisualElement newElement) [0x00080] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\RendererPool.cs:78
at Xamarin.Forms.Platform.iOS.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00050] in D:\agent_work\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:1

How to reproduce

So - this bug is easily reproducible - I've tested on a live iPhone X and also simulators running 11.2. Quite simply, just create a navigation page that navigates to a content page. On this content page - just have a simple TableView with 3-4 sections. In Each section - have about 5-8 ViewCells with a grid that defines two star based columns.

Then ensure that the Grids that you have for each ViewCell mixes up a combination of Labels and BoxViews, and Labels and Switches, i.e

**

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Label
                            Grid.Column="0"
                            HorizontalOptions="Start"
                            Text="Message 1" />

                        <BoxView
                            Grid.Column="1"
                            BackgroundColor="Red"
                            HeightRequest="30"
                            Scale="1"
                            WidthRequest="30" />
                    </Grid>

**

Run App
So once you have deployed the APP onto a device/simulator - to get the app to crash - you need to rapidly hold your finger on your screen and swipe up and down so that the TableView contents will move up and down - doing this for a few seconds will give you the crash.

For your convenience, I have attached the complete View to this post - I use Prism so if you dont use that, just remove the references to Prism in the ContentPage header and you will be all set .

Our app has loads of ViewCells and they are all broken beyond repair - running under XF 2.3.4.270 , the issue doesnt arise - this issue coupled with the outstanding GestureRecognizer issue in Android whereby touch events just dont work (Any UI elements where GR's are attached, you need to touch the controls 5-8 times before the event is raised!) means that we cannot move past XF 2.3.4.270 as there currently isnt a XF version post this that fixes these and all the other issues....

Sample UI

How to deploy my ios app to Iphone without using Mac ?

$
0
0

I developed a cross platform app(uwp,android,ios) using Xamarin.forms .I published uwp and android without any issues,now i want to publish ios app as .ipa file ,i couldn't find any way for doing this (Note: I don't have a mac system and I don't have enough money to buy it) .

Thus the main thing is that I want to deploy a .ipa file so that i can test my ios app with my friends mobile (Iphone),Please give me some suggestions.

I am using VS2017 xamarin 2.5 stable version .

Viewing all 58056 articles
Browse latest View live


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