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

I got this error: "Guid" can not be converted to type 'System.String' Also what is this other error?

$
0
0

Hello everyone, I am just a beginner in programming with xaml and I need help to understand this things I am encountering during programming, and to know how to solve them.

I am trying to bind in my xaml a collection from my observablecollection that has a property guid, I cannot actually display it since only takes string, my question is what code can I use to convert guid into string?

<ListView x:Name="listView" SeparatorVisibility="None">
        <ListView.ItemTemplate>
            <DataTemplate>
        <TextCell Text="{Binding Guid}" TextColor="Black" />
        <TextCell Text="{Binding String}" TextColor="Black" />
        </DataTemplate>
        </ListView.ItemTemplate>
</ListView>

And also if I add two text cell in xaml, this error or blue lines shows up:
"The property 'ElementTemplateContent' is set more than once" Is this because I am using listview? and from what I observed, the collection added in my observablecollection which is the itemsource in this case, displays "Guid" (But only shows with an empty text), then displays "String" (with a text) even if I just use this one line of xaml code.

<TextCell Text="{Binding String}" TextColor="Black" />

Thanks in advance!


Can't Run My App on Android 5.1 (API 22)

$
0
0

Installed from signed APK

Target Framework: Android 8.1
Target Android Version: Android 8.1
Minimum Android Version: Android 4.4

This is the error i get from device log tool:

System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0006f] in <99988d4ab8d144898ef5bc7586876d75>:0 
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <99988d4ab8d144898ef5bc7586876d75>:0 
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <99988d4ab8d144898ef5bc7586876d75>:0 
  at SampleApp.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00028] in <eaa39f9ef27d400ebfed424165f990c2>:0 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <818821ea7e204c78a45bc29cdc69e744>:0 
  at (wrapper dynamic-method) System.Object.fe8f1617-954f-4716-901a-433b7f8b44bf(intptr,intptr,intptr)

Is there a beforeClass method() in XamarinUITest

$
0
0

Hello,
In XamarinUITest I was wondering is there a method that I can run when the class loads and before any of the test runs like @BeforeClass in testng
I don't want to use the constructor.

Issue with a splashscreen and a webview

$
0
0

Hello,

As a sample, I use this project : https://github.com/ozaksuty/Xamarin-Ogreniyorum/tree/master/XamarinTRMenu

In the detail.xaml in PCL, I replace all items by a webview for amazon.com

As I don't want to have a white area before the loading of the page when I launch the app, I want to add a splashscreen for all the app, toolbar included.

I manage to add a view with a logo as Image and media in the resources folder, and a custom activity in the Droid solution with MainLaucher at true and no theme for the MainActivity/ MainLaucher at false, with a style to display a picture.

Next, in my App.cs or App.xaml.cs, I set the MainPage to my SplashScreen and now I need your help to start the navigation and when it's finish, to remove my splashscreen from the view.

I don't find any event to force the navigation, so my application always stay on the splashscreen view and never change.

Could you help me ?

Regards

How to add images to a story board?(Launching screen)

$
0
0

I follow the following blog for creating IOS splash: https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=vsmac

I created a new launching screen file for my xamarin forms app, but can't see any option for adding an image for launching screen. Adding a screenshot of my current screen:

From where I can see the menu options for adding an image? I open it by double-clicking the file. When I run showing a blank white screen as the splash screen.

Also, I try to create the launching screen by adding all the images specified in the Assets.xcassets file, adding a screenshot of that:

Thanks in advance :)

How do I make proper bullet points in a StackLayout class?

$
0
0

Someone suggested to use the StackLayout class to do bullets in my last post.

https://forums.xamarin.com/discussion/74420/what-is-the-best-way-to-format-text-in-xamarin-forms#latest

I am trying to do this, but when I do bullets, the text wraps around to the margin instead of to the right edge of the bullet like in Word documents. Example of a proper bullet:

  • Xamarin is a Microsoft-owned San Francisco, California-based software company founded in May 2011[3] by the engineers that created Mono,[4] Mono for Android and MonoTouch that are cross-platform implementations of the Common Language Infrastructure (CLI) and Common Language Specifications (often called Microsoft .NET).

This is what happens when I use my code.

• Xamarin is a Microsoft-owned San Francisco, California-based software company founded in May 2011[3] by the engineers that created Mono,[4] Mono for Android and MonoTouch that are cross-platform implementations of the Common Language Infrastructure (CLI) and Common Language Specifications (often called Microsoft .NET).

I have been experimenting with the BulletedList class, but it does not want to seem to want to fit in the main class. This is an example of the code I am using right now.

using System;
using Xamarin.Forms;

namespace FormsGallery
{

public class MyClass : ContentPage
{
    public MyClass()
    {
        Label header = new Label
        {
            Text = "MyClass",
            FontSize = 36,
            FontAttributes = FontAttributes.Bold,
            HorizontalOptions = LayoutOptions.Center
        };

        ScrollView scrollView = new ScrollView
        {

            Content = new StackLayout()
            {
                Spacing = 0,
                Padding = 0,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children = {

                        new Label
                        {

                        Margin = new Thickness (20),
                        FontSize = 16,
                        Text = "\u2022 Xamarin is a Microsoft-owned San Francisco, California-based software company founded in May 2011[3] by the engineers that created Mono,[4] Mono for Android and MonoTouch that are cross-platform implementations of the Common Language Infrastructure (CLI) and Common Language Specifications (often called Microsoft .NET).\n",

                    },

                        }
            }

        };

        // Build the page.

        this.Content = new StackLayout
        {
            Children =
            {
                header,
                scrollView,
            }
        };
    }
}

}

NavigationBar Background Image Renderer Android

$
0
0

Hi Guys,

I have been working on Xamarin Forms and I wanted to set an image as background image into navigation bar but I couldn't I have tried a lot but no luck at that time.

Then something hit in my mind and I tried and that works pretty charms! You just need to make a renderer and there a single method will help you.

Have a look :)

Android

    [assembly: ExportRenderer(typeof(ContentPage), typeof(ContentPageRenderer))]
    namespace MyApp.Renderers
    {
        public class ContentPageRenderer : PageRenderer
        {
            protected override void OnLayout(bool changed, int l, int t, int r, int b)
            {
                    base.OnLayout(changed, l, t, r, b);
                    var actionBar = ((Activity)Context).ActionBar;
                    actionBar.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.YourImageInDrawable));
            }
        }
    }

iOS

    [assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(BlueNavigationRenderer))]
    namespace MobileCRM.iOS.Renderers
    {
        public class BlueNavigationRenderer : NavigationRenderer
        {

            public override void ViewDidLoad()
            {
                base.ViewDidLoad();

                this.NavigationBar.BarTintColor = UIColor.FromPatternImage(UIImage.FromFile("topbar_bg@2x.png"));
             }
          }
     }

Here we go!! :D This post will help you to customize you navigation bar.

ToolbarItem Icon EmbeddedResource

$
0
0

Hello,

i'm trying to add a ToolbarItem to a NavigationPage. This ToolbarItem should have an Icon from an EmbeddedResource-Image.
I made an fresh Xamarin.Forms MasterDetail Project and added the image, ImageResourceExtension and the ToolbarItems code in the XAML file like this:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns:views="clr-namespace:App1.Views"
            xmlns:local="clr-namespace:App1"
            x:Class="App1.Views.MainPage">
    <TabbedPage.Children>
        <NavigationPage Title="Browse">

            <NavigationPage.ToolbarItems>
                <ToolbarItem Text="Here has to be a logo" Icon="{local:ImageResource Source=App1.home.png}" />
            </NavigationPage.ToolbarItems>

        </NavigationPage>      
    </TabbedPage.Children>
</TabbedPage>
 [ContentProperty(nameof(Source))]
    public class ImageResourceExtension : IMarkupExtension
    {
        public string Source { get; set; }

        public object ProvideValue(IServiceProvider serviceProvider)
        {
            if (this.Source == null)
            {
                return null;
            }

            var imageSource = FileImageSource.FromResource(this.Source);

            return imageSource;
        }
    }

Do someone give me a hint why the image is not displayed?


How to add back button to the content page navigation bar

$
0
0

Hi, I am new to forms My question is how to add back button to the content page navigation bar. My Main page is like
MainPage = new NavigationPage(new LoginPage()); .
My LoginPage is content page. I want to add back button to the loginpage navigation bar. I using NavigationPage.SetHasBackButton(this, true); but it not showing any back button. And also how to send the data form page2 to page1 by using Navigation.PopModalAsync();

Thank you.

How to manage maps with private areas?

$
0
0

Hello,

A client contacted me because he would like an app allowing him to use maps to display and locate "private areas" (like plots for a farmer) through layers drawn on the map.

The expected result is something like this:

To achieve this, I need:

  • a admin web app allowing administrators to define these areas
  • a map that should get and display these areas in the mobile app

The easyer way to achieve must to use GoogleMaps:

  • I've seen that we can define polygons on a web app
  • there's the TK.CustomMap plugin allowing to draw shapes on a Google map

=> but I don't see how to get the areas defined from the web app for draw them on the mobile app

I also looked for other solutions:

  • MapBox and the related Xamarin.Forms plugin
  • ThinkGeo which seems very complete but very expensive too
  • ArcGis, that seems interesting in a .Net environment

But I didn't found a similar case than mine, where areas were defined from a web app, and displayed on the mobile app.

=> Would you have any suggestion? What would be the better approach to achieve this?

ListView separator full width iOS

$
0
0

Hi! Its possible to get a full width separator in iOS?

I implemented a custom renderer but not solved. When I debug CellLayoutMarginsFollowReadableWidth, its already false.

https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/ios/ipad-listview/

https://forums.xamarin.com/discussion/comment/159290/#Comment_159290

My custom renderer is:

using CustomRenderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using ListViewRenderer = CustomRenderers.ListViewRenderer;

[assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer))]
[assembly: ExportRenderer(typeof(TableView), typeof(UITableViewRenderer))]

// [HACK]: Needed because of a bug in Xamarin
namespace CustomRenderers
{
    public class ListViewRenderer : Xamarin.Forms.Platform.iOS.ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
                return;

            var tableView = Control as UITableView;

            tableView.CellLayoutMarginsFollowReadableWidth = false;
        }
    }

    public class UITableViewRenderer : Xamarin.Forms.Platform.iOS.TableViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
                return;

            var tableView = Control as UITableView;

            tableView.CellLayoutMarginsFollowReadableWidth = false;
        }
    }
}

Any ideas?

Xamarin Forms 2.3.5.256-pre6
iPhone 5 iOS 9.1

How to apply border to textbox(Entry) xamarin forms.

$
0
0

Hi,
How to apply a border to textbox(Entry) and get normal textbox with border. Is there any way to do that?

ListView can make a phone call

$
0
0

Hi Xamarin Forum
may I ask if it is possible I have a list of contact made out of ListView then lets say I have a searchbar then I search for my ListView records for a contact then I will tap on the number in that listview is that possible? if it is possible how? can some one give an idea

Push Notification that really works

$
0
0

Hello everyone,

along these 4 days i tried every plugin and component that Xamarin and others provide to work with push notification and no one of them works.

i've tried Azure Message, Azure Web Services, Push Notification Plugin Xamarin and many others and nothing...

lemoncode.net/2015/04/17/adding-push-notifications-to-your-xamarin-forms-application-part-1/

https://github.com/Redth/PushSharp

https://github.com/rdelrosario/xamarin-plugins/tree/master/PushNotification

the only that really does not install is this: http://www.c-sharpcorner.com/UploadFile/761867/xamarin-push-notifications-using-azure-notifications-hub/

when i will install i am getting this error:

install-Package : Could not install package 'Microsoft.WindowsAzure.ConfigurationManager 3.1.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v5.0', but the package
does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

We really need something good to start =/

thanks

ListView Scroll issue (middle of the screen)

$
0
0

List view works fine except cannot scroll down (scrolling up is fine) from the middle of the screen. Can scroll from left or the right side of the screen. I know it's weird. Anybody dealt with this issue? Thanks.


ListView keep space when user click in Entry in Xamarin.Form(Check in iOS)

$
0
0

I have application where there is chat page. On the page, I use ListView with DataTemplate to show incoming and outgoing message. Now the problem is when I click on Entry(Textbox) where user can write message, keyboard opens and my ListView keep space between last message and Entry.

I have read few blogs and example of chat but none having consistent behavior.

Code:

<ContentPage.Resources>
<ResourceDictionary>
  <local:MessageTemplateSelector x:Key="MessageTemplateSelector" />
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
    <StackLayout>
      <ListView x:Name="MessagesListView"
                ItemTemplate="{StaticResource MessageTemplateSelector}"
                ItemsSource="{Binding Messages}"
                HasUnevenRows="True"
                ItemSelected="MyListView_OnItemSelected"
                ItemTapped="MyListView_OnItemTapped"
                IsPullToRefreshEnabled="true"
                IsRefreshing="{Binding IsRefreshing}"
                RefreshCommand="{Binding RefreshCommand}"
                SeparatorVisibility="None"
                BackgroundColor="{DynamicResource d8GreyLight}"
                //RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=1,Constant=0}"
        />

      <Grid x:Name="MessageControls" RowSpacing="1" ColumnSpacing="2" Padding="5"
            BackgroundColor="#EFEFF4"
            VerticalOptions="FillAndExpand"
            HorizontalOptions="FillAndExpand">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Entry x:Name="txtMessage" Grid.Column="0" HeightRequest="40" Placeholder="Message" Text="{Binding OutGoingText}" TextChanged="EnableSend"/>
        <Frame x:Name="SendButton">
          <Frame.GestureRecognizers>
            <TapGestureRecognizer Tapped="SendMessage_Click" NumberOfTapsRequired="1" />
          </Frame.GestureRecognizers>
          <Label Text="Send"/>
        </Frame>
      </Grid>
    </StackLayout>

</ContentPage.Content>

Way-1: KeyboardRendering for MessagePage: Keep Space between ListView last message and SendTextBox

using Project;
using Project.iOS;
using CoreGraphics;
using Foundation;
using System;
using UIKit;
using Xamarin.Forms;


[assembly: ExportRenderer(typeof(MessagePage), typeof(KeyboardAdaptedPageRenderer))]
namespace Project.iOS
{
    public class KeyboardAdaptedPageRenderer : ContentPageWithCustomBackButtonRenderer
    {
        //Way-1: Keep Space between ListView last message and SendTextBox
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            Keyboard.WillShow += OnKeyboardWillShow;
            Keyboard.WillHide += OnKeyboardWillHide;
        }

        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            Keyboard.WillShow -= OnKeyboardWillShow;
            Keyboard.WillHide -= OnKeyboardWillHide;

            OnKeyboardWillHide(new KeyboardInfo()
            {
                AnimationDuration = 0,
                AnimatonOptions = UIViewAnimationOptions.TransitionNone
            });
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            Keyboard.WillShow -= OnKeyboardWillShow;
            Keyboard.WillHide -= OnKeyboardWillHide;
        }

        private void OnKeyboardWillShow(KeyboardInfo info)
        {
            NSThread.SleepFor(1);
            if (info.SoftwareKeyboardIsVisible)
            {
                UIView.Animate(info.AnimationDuration, 0, info.AnimatonOptions, () =>
                {
                    var bounds = View.Bounds;
                    bounds.Y = info.BeginRect.Top - info.EndRect.Top; // iphone 4 and others
                    View.Bounds = bounds;
                }, null);
            }
        }

        private void OnKeyboardWillHide(KeyboardInfo info)
        {
            NSThread.SleepFor(1);

            UIView.Animate(info.AnimationDuration, 0, info.AnimatonOptions, () =>
            {
                var bounds = View.Bounds;
                bounds.Y = 0;
                View.Bounds = bounds;
            }, null);
        }
    }
}

Result

enter image description here

Way-2: KeyboardRendering for MessagePage: Design of SendTextBox issue when keyboard up and down

using Project;
using Project.iOS;
using CoreGraphics;
using Foundation;
using System;
using UIKit;
using Xamarin.Forms;


[assembly: ExportRenderer(typeof(MessagePage), typeof(KeyboardAdaptedPageRenderer))]
namespace Project.iOS
{
    public class KeyboardAdaptedPageRenderer : ContentPageWithCustomBackButtonRenderer
    {   
        //way-2 Error: Space issue is solved but not consistant in design of SendTextbox in         way-1
        NSObject observerHideKeyboard;
        NSObject observerShowKeyboard;


        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var cp = Element as ConversationPage;
            if (cp != null && !cp.CancelsTouchesInView)
            {
                foreach (var g in View.GestureRecognizers)
                {
                    g.CancelsTouchesInView = false;
                }
            }
        }

        public override void ViewWillAppear(bool animated)
        {

            base.ViewWillAppear(animated);

            observerHideKeyboard = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification);
            observerShowKeyboard = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification);
        }

        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);

            NSNotificationCenter.DefaultCenter.RemoveObserver(observerHideKeyboard);
            NSNotificationCenter.DefaultCenter.RemoveObserver(observerShowKeyboard);
        }

        void OnKeyboardNotification(NSNotification notification)
        {
            if (!IsViewLoaded) return;

            var frameBegin = UIKeyboard.FrameBeginFromNotification(notification);
            var frameEnd = UIKeyboard.FrameEndFromNotification(notification);

            var page = Element as ContentPage;
            if (page != null && !(page.Content is ScrollView))
            {
                var padding = page.Padding;
                NSThread.SleepFor(1);
                page.Padding = new Thickness(padding.Left, padding.Top, padding.Right, padding.Bottom + (frameBegin.Top - frameEnd.Top));
            }
        }
    }
}

Result:
enter image description here

Xamarin.Forms CardsView nuget package

$
0
0

Hi all) I've released new package for Xamarin.Forms (Something like Tinder's CardsView)
Maybe, someone will be interested in it

nuget.org/packages/CardsView/ -- nuget
github.com/AndreiMisiukevich/CardView -- source and samples

Clicking Cancel button on popup,Go back to the before pop up page?

$
0
0

I have created a PopupPage in xamarin forms..
What I have done ===== >> MainPage(There is a -- Button) --> Clicked **--> **PopupPage opens.
I want to do but can't figure out how==============>>** PopupPage( "Cancel" button)** -->Clicked **-->PopupPage closes** and **MainPage **will be shown..

What code should I write in the "Cancel" button's event in PopupPage.Xaml.cs to go back to MainPage?

Xamarin Forms ListView's ScrollToHeader and ScrollToFooter missing

$
0
0

I want to scroll the listView programmatically to its header and footer element's start & end position. But ListView.ScrollTo method allows to scroll within the itemsource elements. Please anyone help me to achieve it.

Thanks in advance.

Device orientation (Portrait, Landscape) based styling not working on GridView

$
0
0

Hi.

I have a <style> element and I want that if the device in Portrait or in Landscape the Margin of the Grid has different values.

But it seems it does not work, because the margin is always 0.

<ContentView.Resources>
        <ResourceDictionary>
            <Style x:Key="CategoryGridStyle"  x:Name="CategoryGridStyle" TargetType="Grid">
                <Setter Property="ColumnSpacing" Value="10" />
                <Setter Property="RowSpacing" Value="10" />
                <Setter Property="HorizontalOptions" Value="FillAndExpand" />
                <Setter Property="VerticalOptions" Value="FillAndExpand" />
                <!--<Setter Property="Margin" Value="30, 100"/>-->
                <Setter Property="VisualStateManager.VisualStateGroups">
                    <VisualStateGroupList>
                        <VisualStateGroup x:Name="OrientationStates">
                            <VisualState Name="Portrait">
                                <VisualState.Setters>
                                    <Setter Property="Margin" Value="30, 100" />
                                </VisualState.Setters>
                            </VisualState>

                            <VisualState Name="Landscape">
                                <VisualState.Setters>
                                    <Setter Property="Margin" Value="30, 100" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </Setter>

However if I uncomment this line:
<!--<Setter Property="Margin" Value="30, 100"/>--> The margin will works. But I need different margin values on different device orientation :)

Bonus question: is it possible to do with OnIdiom element too? (Detect if it is phone or tablet)

Viewing all 89864 articles
Browse latest View live


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