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

Unfortunately, my Application has stopped!!!

$
0
0

one page of my application it contains carousal view it works fine , but sometime when i move between pages i got this error "unfortunately my application has stopped ".
the problem is : when i use emulator this error does not appear, but when i use my real device this happen sometimes.
another note when i debug the application on the real device and when this error appear , application stopped but didn't go back to the code.

any suggestion please ?


ListViewRenderer dataSource is null

$
0
0

I've been trying to copy the iOS CostomRenderer from IncredibleWeb/Xamarin-Forms-Chat-Client.
The Exception cause is a nullReferenceException, but i've traced the issue to this line:

table.Source = new ListViewDataSourceWrapper(this.GetFieldValue<UITableViewSource>(typeof(ListViewRenderer), "dataSource"));

where GetFieldValue looks like this:

public static T GetFieldValue<T>(this object @this, Type type, string name) {
            var field = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField);
            return (T)field.GetValue(@this);
        }

the field ist what is null and causes the exception to be thrown.

Just before the point of failure, the field also gives this error:

Unable to cast object of type 'System.RuntimeType' to type 'Mono.Debugger.Soft.TypeMirror'.

Googleing this error has yielded no enlightenment.
Values before Error

I am completely at a loss here and don't know which parts of the code might be helpful to figuer this out.!

Any help would be greatly appreciated!

Porting from WPF

$
0
0

Hi I'm new to Xamarin Forms although have some experience with MVVMLight on WPF.

I'm porting an existing WPF application to Xamarin.Forms, and have hit my first (no doubt of many) problem with my Shell View.

In my existing (WPF) application I have a CurrentViewModel property on my ShellViewModel which I bind to a content control in the ShellView.

I then use DataTemplate resources to render the appropriate View in the Conent control like so:

    <ResourceDictionary>
        <DataTemplate DataType= "{x:Type help:HelpViewModel}">
            <help:HelpView />
        </DataTemplate>

        <DataTemplate DataType= "{x:Type home:HomeViewModel}">
            <home:HomeView />
        </DataTemplate>

..etc.

Is it possible to do something similar with Xamarin Forms, the Xamain DataTemplate does not have a DataType property.

Thanks in advance
Dave

Unable to cast object of type 'System.RuntimeType' to type 'Mono.Debugger.Soft.TypeMirror'

$
0
0

Unable to cast object of type 'System.RuntimeType' to type 'Mono.Debugger.Soft.TypeMirror' for _list

var _list= new ObservableCollection
{
new loginDetail
{
name="Rinshad",
email="rinshad06@gmail.com",
c_password="qwer"
},
new loginDetail
{
name="rrr",
email="rshad06@gmail.com",
c_password="wwww"
},
new loginDetail
{
name="laxman",
email="laxman@gmail.com",
c_password="laxmandddd"
},

        };
        return _list;

plz help me out ASAP

Xamarin Forms Map UWP - MapIcon SizeRequest

$
0
0

Hi,

I searched so much and no one seems to have the answer..
How can I set the size of a pin? UWP part of PCL project

Thank in advance !

Map Renderer with custom Pin

$
0
0

Hi to all, I followed this guide: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/map/customized-pin/
to develop my app.
The pins work correctly but when I try to reach my device location on the map, I get a null pointer like this:

System.NullReferenceException: Object reference not set to an instance of an object
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at blind.iOS.Application.Main (System.String[] args) [0x00008] in /Users/alessandroa/Projects/blind/iOS/Main.cs:17

I add my location with this:

    nativeMap.ShowsUserLocation = true;
    nativeMap.SetUserTrackingMode(MKUserTrackingMode.Follow, true);

in the OnElementChanged method.
Any suggestions?

Thanks a lot!

Xamarin Forms Sockets

$
0
0

I don't get it, my friend and I are developing an API and our WebSocket services works, but not the mobile side.. I tried with a couple of clients, on the web, our echo messaging and everything works.

The thing is, I mean, the things seem like the socket is mono-directional. I tried the example of https://github.com/rdavisau/sockets-for-pcl#a-tcp-client:

var address = "127.0.0.1";
var port = 11000;
var r = new Random();

var client = new TcpSocketClient();
await client.ConnectAsync(address, port);

// we're connected!
for (int i = 0; i<5; i++)
{
    // write to the 'WriteStream' property of the socket client to send data
    var nextByte = (byte) r.Next(0,254);
    client.WriteStream.WriteByte(nextByte);
    await client.WriteStream.FlushAsync();

    // wait a little before sending the next bit of data
    await Task.Delay(TimeSpan.FromMilliseconds(500));
}

await client.DisconnectAsync();

First, after I get connected with this :

public async void ConnectSocketToAPIAsync()
    {
        SocketClient = new TcpSocketClient();
        await SocketClient.ConnectAsync("my.ws.service", 4242);
        ActiveSocketExchange();
    }

    public async void ActiveSocketExchange()
    {
        var bytesRead = -1;
        var buf = new byte[1];

        while (bytesRead != 0)
        {
            bytesRead = await SocketClient.ReadStream.ReadAsync(buf, 0, 1);
            if (bytesRead > 0)
                MessagingCenter.Send((App)Current, SOCKET_Message, System.Text.Encoding.UTF8.GetString(buf, 0, bytesRead));
        }
    }

Everything's fine, my TcpClient is well initialized (even the web-link becomes the http's API addr)

From my page view, when I'm done writing my text, I'm pressing the done button of the keyboard and this code is called:

private void InitSocketPart()
    {
        MessagingCenter.Subscribe<App, string>((App)Application.Current, App.SOCKET_Message, (sender, text) =>
        {
            SocketResponseText = text;
        });
    }

    private async void OnTextCompleted(object sender, EventArgs ea)
    {
        var bytes = Encoding.UTF8.GetBytes(TextToSend);
        try {
            if (App.SocketClient.WriteStream.CanRead)
                Debug.WriteLine("canRead");
            if (App.SocketClient.WriteStream.CanWrite)
                Debug.WriteLine("canWrite");

            App.SocketClient.WriteStream.Write(bytes, 0, TextToSend.Length);
            App.SocketClient.WriteStream.Flush();
        } catch (Exception e)
        {
            Debug.WriteLine(e);
        }
    }

So now CanWrite && CanRead are true, but nothing at all happens, even with the use of Async methods... Why so? I don't get it..

The use of messaging center is just to have only one point of incoming message. I'm using it for other things and it works perfectly :)

Thank for any help..

How to display content from one xaml inside another

$
0
0

I'm used to Android development, and am having some difficulty accomplishing what I would think is a simple task.

I have a MasterDetailPage (called ContainerView.xaml).
The Master is my navigation bar (called NavBarView.xaml).
The Details is supposed to be a page with a fixed title bar, and a "view" I can swap per user choices.
The Details page is called MainView.xaml.
The Title I'd like to display at the top and is called TitleBarView.xaml.
Then I have a number of content pages such as Page1View.xaml.

in my ContainerView.xaml:

<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                  x:Class="MyApp.ContainerView"
                  IsGestureEnabled="True"
                  MasterBehavior="Popover"
                  Title="MasterDetail Page">
  <MasterDetailPage.Master>
  </MasterDetailPage.Master>
  <MasterDetailPage.Detail>
  </MasterDetailPage.Detail>
</MasterDetailPage>

in my NavbarView.xaml - this is the Master

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.NavBarView"
             Title="Nav Bar">
  <ContentPage.Content>
    <StackLayout Orientation="Vertical">
      <Label Text="{Binding Item1}"/>
      <Button Text="Options" Command="{Binding Option1Command}"/>
    </StackLayout >
  </ContentPage.Content>
</ContentPage>

in my MainView.xaml - this is the details

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.MainView"
             Title="Main View">
  <ContentPage.Content>
  // what to put here to show the TitleBarView.xaml?
  // what to put here to show my content xaml pages?
  </ContentPage.Content>
</ContentPage>

in my TitleBarView.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.TitleBarView">
  <ContentView.Content>
    <StackLayout Orientation="Horizontal">
      <Label Text="{Binding Item1}"/>
      <Button Text="Options" Command="{Binding OptionsCommand}"/>
    </StackLayout>
  </ContentView.Content>
</ContentView>

and a generic content view, of course there will be many others I want to switch between

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Page1View">
  <ContentView.Content>
    <StackLayout Orientation="Vertical">
      <Label Text="{Binding Info}"/>
      <Button Text="Log In" Command="{Binding GoToPage2Command}"/>
    </StackLayout >
  </ContentView.Content>
</ContentView>

I am using the MVVM model and have this code, but can't seem to get just the basics working.
The Master page displays fine.
If the Details page is just a simple page, it works, but I can't figure out how to insert the TitleBar and swap out the "Content".

ContainerView containerPage = new ContainerView();
ContainerViewModel containerVM = new ContainerViewModel();
containerPage.BindingContext = containerVM;

NavBarView navigationBar = new NavBarView();
navigationBar.Title = "Navigation Bar"; // required, otherwise I get an exception.
NavBarViewModel navigationBarVM = new NavBarViewModel();
navigationBar.BindingContext = navigationBarVM;

MainView mainView = new MainView();
mainView.Title = "MainView";
MainViewModel mainViewVM = new MainViewModel();
mainView.BindingContext = mainViewVM;

TitleBarView titleBar = new TitleBarView();
TitleBarViewModel titleBarVM = new TitleBarViewModel();
titleBar.BindingContext = titleBarVM;

Page1View page1 = new Page1View();
Page1ViewModel page1VM = new Page1ViewModel();
page1.BindingContext = page1VM;

mainView.Content = new StackLayout()
{
    Orientation = StackOrientation.Vertical,
    Children =
    {
        new Label { Text = "I'm Content!" },
        new Label { Text = "I'm Content!" },
        //titleBar.Content,
        //loginView.Content
    }
};

containerPage.MasterBehavior = MasterBehavior.Popover;
containerPage.Master = navigationBar;
containerPage.Detail = new NavigationPage(mainView);

I'm sure I'm missing a fundamental concept. Any help would be appreciated


Navigation Bar Image for iOS

$
0
0

Hi, im trying to include a image on the right side of the navigation bar. For Android I already have a working solution but im struggling to get it done for iOS.
So far I only have found non-Xamarin solutions for this which im not able to convert into my Xamarin project. Also the documentation states that there is something like "RightBarButtonItems" but it seems this only works for smaller icons (while my image would be about 140x60) and I also don't need it as button.

Does someone have a idea how I can include such a image to the right side?

Navigation using listview item tapped....

$
0
0

Hi ,sorry for this type of simple question but i need help related to topic "Navigation on other page using listview items and page should be change dynamically" i,m biggner in xamarin.forms ....thanx in advance.

Can We use Redis in xamarin forms ?

$
0
0

Im Curious can we use redis in xamarin forms, because i cant find any discussion or solution for that . What i find is Akavache for xamarin forms wich is great tool for caching data , but the question is can we use redis for xamarin forms ?

Refresh ListView on another contentPages via button click event

$
0
0

Hello, I am having a hard time making my app to refresh a listview in ContactListPage via Return button click event in NewContactPage. Save button in NewContactPage seems to be working fine based on the list of items I get out of Debug.Writeline output. I've tried ObservableCollection instead of using List for contacts but it didn't help.
It would be very much appreciated if someone can point me in the right direction.

public class ContactListPage : ContentPage
    {
        public ListView listView = new ListView();
        public List<Contact> contacts = new List<Contact>();
        public StackLayout layout = new StackLayout();
        public ContactListPage()
        {
            Button button = new Button
            {
                Text = "Add Contact",
                Margin = new Thickness(0, 0, 10, 0)
            };
            button.Clicked += OnButtonClicked;

            StackLayout buttonLayout = new StackLayout { Orientation = StackOrientation.Horizontal, VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    new Label {Text = "Contact List"},
                    button
                }
            };

            // Add existing contacts
            contacts.Add(new Contact("Jason", "Born", "Family"));
            contacts.Add(new Contact("Sunny", "An", "Family Dog"));
            contacts.Add(new Contact("Jenny", "Bahn", "Family"));
            contacts.Add(new Contact("Joshua", "Brown", "Work"));

            // Set up listview
            listView.ItemsSource = contacts;
            listView.ItemTemplate = new DataTemplate(typeof(TextCell));
            listView.ItemTemplate.SetBinding(TextCell.TextProperty, "FullName");
            listView.ItemTemplate.SetBinding(TextCell.DetailProperty, "ContactType");
            listView.HeightRequest = (40 * contacts.Count);

            // Add things to the stacklayout
            layout.Children.Add(buttonLayout);
            layout.Children.Add(listView);

            Content = layout;

            void OnButtonClicked(object sender, EventArgs args)
            {
                Navigation.PushAsync(new NewContactPage());
            };
        }
    }


public class NewContactPage : ContactListPage
    {
        public NewContactPage()
        {
            EntryCell firstName = new EntryCell
            {
                Label = "First Name:",
                Keyboard = Keyboard.Default
            };
            EntryCell lastName = new EntryCell
            {
                Label = "Last Name:",
                Keyboard = Keyboard.Default
            };
            EntryCell contactType = new EntryCell
            {
                Label = "Contact Type:",
                Keyboard = Keyboard.Default
            };
            Label firstLabel = new Label{Text = ""};
            Label secondLabel = new Label{Text = ""};

            TableView tableView = new TableView
            {
                VerticalOptions = LayoutOptions.Start, Intent = TableIntent.Form, Root = new TableRoot("Table Title") {
                    new TableSection ("Add a New Contact") { firstName, lastName, contactType }}
            };

            // Setup buttons
            Button saveContactButton = new Button { Text = "Save Contact", WidthRequest = 150, Margin = new Thickness(50, 0, 0, 0) };
            saveContactButton.Clicked += saveContactButtonClicked;
            Button returnButton = new Button { Text = "Return", WidthRequest = 150, Margin = new Thickness(10, 0, 50, 0) };
            returnButton.Clicked += returnButtonClicked;

            StackLayout buttonLayout = new StackLayout { Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.Start,
                Children =
                {
                    saveContactButton,
                    new Label {Text = ""},
                    returnButton
                }
            };

            Content = new StackLayout
            {
                Children = { tableView, buttonLayout, firstLabel, secondLabel }
            };

            void saveContactButtonClicked(object sender, EventArgs e)
            {
                try
                {
                    // Add new contact to list
                    contacts.Add(new Contact(firstName.Text.ToString(), lastName.Text.ToString(), contactType.Text.ToString()));

                    // Remove texts
                    firstName.Text = String.Empty;
                    lastName.Text = String.Empty;
                    contactType.Text = String.Empty;
                    DisplayAlert("Success", "New contact has been added.", "OK");
                }
                catch(Exception ex)
                {
                    Debug.WriteLine("Exception: {0}", ex);
                }
            };

            void returnButtonClicked(object sender, EventArgs e)
            {
                layout.Children.Remove(listView);
                listView.ItemsSource = null;
                listView.ItemsSource = contacts;
                layout.Children.Add(listView);
                Navigation.PopAsync();
            };

        }
    }


public class Contact
    {
        // constructor
        public Contact(string firstName, string lastName, string contactType)
        {
            FirstName = firstName;
            LastName = lastName;
            ContactType = contactType;
        }
        // properties
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string ContactType { get; set; }
        public string FullName
        {
            get { return FirstName + " " + LastName; }
            set { FullName = value; }
        }
    }

How to make Round corner Entry Control Xamarin.Forms

$
0
0

I want to make Round corner Entry Control Xamarin.Forms,please some one help me in this issue

Could not locate D:\Visual Studio 2017\AppName\AppNaem\AppName.Uwp\packages.config

$
0
0

Hi, I am getting this error after build and I cannot run the app because of it :

Could not locate C:\Visual Studio 2017\AppName\AppName\AppName.UWP\packages.config. Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file.

Do you have any solutions ?

Thanks for answers !!!

How to Use Navigation Push ASync in Master Detail Page Menu

$
0
0

I want to make my xamarin forms app when the menu item is clicked instead change the master detail page it go to another page and shows navigation bar with back button in the top. but i got confused in how to change the on menu item selected, here is my onmenuitemSelected

private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
{

        var item = (DrawerItem)e.SelectedItem;
        Type page = item.TargetType;

        //Navigation.PushAsync((Page)Activator.CreateInstance(page));
        //new NavigationPage((Page)Activator.CreateInstance(page));

        Detail = new NavigationPage((Page)Activator.CreateInstance(page));
       IsPresented = false;
    }

As you can see in the comment tag i already try to do Navigation.Push async and tried New NavigationPage only without Detail but when im click the menu item its do nothing, so what code should i write to do that.


Using StringFormat in Xaml on a Binding

$
0
0

So I've got this:

<Label Text="{Binding CreationDate, StringFormat=HH:mm:ss}" Font="15,Bold" />

Where CreationDate is a DateTime.. But I keep just getting HH:mm:ss

This is how I would expect to use it in Xaml.. What is the correct way to use this?

label text not loading Properly on scrolling of ListView Xamarin Form.

$
0
0

Dear All,
Inside ListView we have Usage 4 label and 3 Images. When We fast Scrolling then some of text not showing properly. inside a ListView please help how to solve this. here is my XAML Code.


<ListView.ItemTemplate>


<ViewCell.View>

                                <Grid BackgroundColor="#EAEBED" RowSpacing="0" ColumnSpacing="0" HeightRequest="50">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="5*"/>
                                        <RowDefinition Height="5*"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions >
                                        <ColumnDefinition Width="2*" ></ColumnDefinition>
                                        <ColumnDefinition Width="5*"></ColumnDefinition>
                                        <ColumnDefinition Width="2*"></ColumnDefinition>
                                        <ColumnDefinition Width="1*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <Image Source="{Binding UserImage}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" HorizontalOptions="Center" ></Image>
                                    <Label Text="{Binding Name}" TextColor="Black" FontSize="11" FontAttributes="Bold" Grid.Row="0"  Grid.Column="1" HorizontalOptions="StartAndExpand" VerticalOptions="Center" >
                                        <Label.GestureRecognizers>
                                            <TapGestureRecognizer Command="{Binding navmesagescreen}" NumberOfTapsRequired="1" />
                                        </Label.GestureRecognizers>
                                    </Label>
                                    <Label Text="{Binding Text}" TextColor="Black" FontSize="9" FontAttributes="Bold" Grid.Row="1"  Grid.Column="1" HorizontalOptions="StartAndExpand" VerticalOptions="Start" >
                                        <Label.GestureRecognizers>
                                            <TapGestureRecognizer Command="{Binding navmesagescreen}" NumberOfTapsRequired="1" />
                                        </Label.GestureRecognizers>
                                    </Label>
                                    <Grid Grid.Column="2" Padding="0,0,2,0" Grid.Row="0" >
                                        <Label Text="{Binding Date}" TextColor="Black" FontSize="8" FontAttributes="Bold" HorizontalOptions="EndAndExpand" VerticalOptions="End" ></Label>
                                    </Grid>
                                    <Grid Grid.Column="2" Padding="0,0,2,0" Grid.Row="1" >
                                        <Label Text="{Binding Time}" TextColor="Black" FontSize="8" FontAttributes="Bold"   HorizontalOptions="EndAndExpand" VerticalOptions="Start" ></Label>
                                    </Grid>
                                    <BoxView HeightRequest="500" WidthRequest="1" BackgroundColor="Black" Grid.Row="0" Grid.Column="3" Grid.RowSpan="2" HorizontalOptions="Start"></BoxView>
                                    <Image Source="{Binding flag}" Grid.Row="0" Grid.Column="3" HorizontalOptions="Center" />
                                    <BoxView HeightRequest="1" WidthRequest="250" BackgroundColor="Gray" Grid.Row="0" Grid.Column="3" HorizontalOptions="Start" VerticalOptions="End"></BoxView>
                                    <Image Source="{Binding Alerticon}" Grid.Row="1" Grid.Column="3" HorizontalOptions="Center" >
                                    </Image>
                                </Grid>

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

Entry binding Decimal

$
0
0

I'm a problem, in my view Model have decimal property

private decimal number1;
public decimal Number1{
            get{ return number1;}
            set{
                number1 = value;
                this.Notify();
            }
        }

xaml

<Entry Placeholder="Value Number"
                       Keyboard="Numeric"
                       Text="{Binding Number1}"/>

but when I'm binding my entry displays this message: "Binding: can not be converted to type 'System.Decimal"

How to read excel file in xamarin forms. In Android platform?

$
0
0

I am trying to read excel file in android. I want to read excel file and store in dataset. I am unable to read excel file in android, i tried using interop but not able to install it. Please help.

How can i make an overlay animation?

$
0
0

Hello, I just started with Xamarin because my teacher forced me and... well what can i say i spent 24hours just to make a simple login screen.
but back to the topic: i want to make an animation to change screens. I made 2 sliding doors. They close, then the screen has to change, then they slide open again.
I tried EVERYTHING! combining the animated images in an absolutelayout with the rest of the content, changing between contents, some animation pipeline but it just won't work.
I bet i'm doing the screen switching wrong too because i just reset the content property of my main page.

Viewing all 77050 articles
Browse latest View live


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