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

How to create a bottom toolbar using Xamarin.Forms for Android

$
0
0

Hi,

I've been working on two Xamarin forms projects and both require a bottom toolbar across iOS and Android. I've been struggling to put together the bottom toolbar for Android using Xamarin forms. I tried to write a custom TabbedRenderer for Android but can't seem to find the right method to override to push the tabs to the bottom. I also tried to use a StackLayout at the bottom of every page for the tabs but the result doesn't look very good - when switching tab, the tabs flash as they are loaded as part of the page.

Is there any better solution for writing a bottom toolbar with Xamarin forms or is there a "native" bottom toolbar coming with Xamarin forms in the near future as Google is now officially embracing bottom navigation with an update to the Material Design spec.?

Thanks!
Jeffrey

using System;
using Xamarin.Forms.Platform.Android;
using Android.App;
using Xamarin.Forms;

[assembly: ExportRenderer(typeof(TabbedPage), typeof(ylbCross.Droid.CustomTabRenderer))]

namespace MyApp.Droid
{
    public class CustomTabRenderer : TabbedRenderer
    {
        private Activity _activity;

        protected override void OnElementChanged (ElementChangedEventArgs<TabbedPage> e)
        {

            base.OnElementChanged (e);

            _activity = this.Context as Activity;


        }

        public override void OnWindowFocusChanged(bool hasWindowFocus)
        {
            ActionBar actionBar = _activity.ActionBar;

            if (actionBar.TabCount > 0)
            {
                ActionBar.Tab tabOne = actionBar.GetTabAt(0);
                tabOne.SetIcon (Resource.Drawable.home_Blue48);

                tabOne.TabSelected += (sender, e) => {
                    tabOne.SetIcon (Resource.Drawable.home_Blue);
                };
                tabOne.TabUnselected += (sender, e) => {
                    tabOne.SetIcon (Resource.Drawable.home_Grey);
                };

                ActionBar.Tab tabTwo = actionBar.GetTabAt(1);
                tabTwo.SetIcon (Resource.Drawable.QA_Grey);
                tabTwo.TabSelected += (sender, e) => {
                    tabTwo.SetIcon (Resource.Drawable.QA_Blue);
                };
                tabTwo.TabUnselected += (sender, e) => {
                    tabTwo.SetIcon (Resource.Drawable.QA_Grey);
                };

                ActionBar.Tab tabThree = actionBar.GetTabAt(2);
                tabThree.SetIcon(Resource.Drawable.consulting_Grey);
                tabThree.TabSelected += (sender, e) => {
                    tabThree.SetIcon (Resource.Drawable.consulting_Blue);
                };
                tabThree.TabUnselected +=   (sender, e) => {
                    tabThree.SetIcon (Resource.Drawable.consulting_Grey);
                }

                ActionBar.Tab tabFour = actionBar.GetTabAt(3);
                tabFour.SetIcon(Resource.Drawable.aboutMe_Grey);
                tabFour.TabSelected += (sender, e) => {
                    tabFour.SetIcon (Resource.Drawable.aboutMe_Blue);
                };
                tabFour.TabUnselected +=    (sender, e) => {
                    tabFour.SetIcon (Resource.Drawable.aboutMe_Grey);
                }

            }

            base.OnWindowFocusChanged(hasWindowFocus);
        }
    }
}

Null reference exception when calling "webClient.DownloadFileTaskAsync" method from custom renderer

$
0
0

I am trying to download an image url from my custom renderer class in Xamarin.iOS class.
When the below is called a Null reference exception is coming and going to App delegate class.

await webClient.DownloadFileTaskAsync (uri, filename);

Even when the above code is kept inside a try block, the exception is not being caught by the catch block

Any idea on how to solve this?

The url will give show an inmage if invokde through a browser.

Compile Error after upgrading to new Xamarin 4.0 and Forms 2.0

$
0
0

I've upgraded everything on the Mac and VS2013 with latest from Xamarin. Now getting the following error when compiling the iOS project. I've submitted a support request at ios@xamarin.com, but thought maybe someone has seen this and can point me in the right direction.

Error 3 Failed to resolve "UIKit.UITextAlignment Xamarin.Forms.Platform.iOS.Extensions::ToUITextAlignment(Xamarin.Forms.TextAlignment)" reference from "Xamarin.Forms.Platform.iOS, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null" C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 664 3

Thanks in advance!

Custom Carousal Page

$
0
0

I want to create a customized carousal page.

The page swipe action will have the default behaviour. But i want to keep a layout with control(for eg Button)
on top the Carousal Page. and this layout should stay there for all the child pages of the carousal.
While swiping only the portions other than this layout should move.

How can i implement that?

Using DataTrigger in XAML

$
0
0

Using 1.3, I'm trying to create a data trigger in XAML but I keep getting exceptions related to the TargetType.

I first tried this:

<controls:WImage Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" HeightRequest="150" Aspect="AspectFill">
  <controls:WImage.Source>
    <UriImageSource Uri="{Binding ImageUrl, Converter={StaticResource StringToUriConverter}}" />
  </controls:WImage.Source>
  <controls:WImage.Triggers>
    <DataTrigger TargetType="controls:WImage" Binding="{Binding ImageUrl}" Value="{x:Null}"  >
      <Setter Property="IsVisible" Value="False" />
    </DataTrigger>
  </controls:WImage.Triggers>
</controls:WImage>

But it said Position 161:20. The Property TargetType is required to create a Xamarin.Forms.DataTrigger object.

Then I tried using

<controls:WImage Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" HeightRequest="150" Aspect="AspectFill">
  <controls:WImage.Source>
    <UriImageSource Uri="{Binding ImageUrl, Converter={StaticResource StringToUriConverter}}" />
  </controls:WImage.Source>
  <controls:WImage.Triggers>
    <DataTrigger TargetType="{x:Type controls:WImage}" Binding="{Binding ImageUrl}" Value="{x:Null}"  >
      <Setter Property="IsVisible" Value="False" />
    </DataTrigger>
  </controls:WImage.Triggers>
</controls:WImage>

But it says key not found, so it doesn't seem to like x:Type.

I'm trying to hide the image element if the ImageUrl is null. This is all inside a DataTemplate, any ideas?

FWIW, WImage is my wrapper to fix the OOM exceptions that I mentioned in this thread.

Any disadvantages to using MessagingCenter?

$
0
0

I've been writing apps using Forms for over a year now - but I haven't used MessagingCenter yet.
I am using the standard .Net way of sending and subscribing to events. If I need to subscribe to an event I need to have a reference to the object that is raising it.
From what I see MessagingCenter could completely decouple objects and allow communication between them.

The disadvantages I see are:
1) The classes will have a dependency to Xamarin.Forms (which is fine for ViewModels - they probably already depend on XF )
2) Unit testing is made difficult - how could Messages be sent when testing? Would MessagingCenter have to wrapped in order to test?

Is it worth using MessagingCenter - am I missing out?

List view with images with custom Good Dynamics httphandler slowwwww

$
0
0

We have a list view displaying user information including an avatar. Because we need to get the data via the custom Good HttpHandler we can't use default image controls. So to this end we've overridden the default image class and added our own bindable source attribute GDImageSource populating the image base classes source property with the stream that is returned from the GDHttpHandler.

The list view ends up being very unresponsive, the scrolling is very choppy.

protected override void OnBindingContextChanged ()
    {
        base.OnBindingContextChanged ();
        // When bound, stream in the Image via GenericHttpHandler
        base.Source = new StreamImageSource() {
            Stream = async (token) =>
                await ServiceLocator.Instance.Resolve<IGenericHttpHandler> ().GetStreamAsync (this.GDImageSource)
        };
    }

Cursor in Editor is invisble on Phone running Lollypop

$
0
0

Hi,

pretty strange, on my Phone running Lollypop the cursor of an Editor is invisble. On my Kitkat Phone it's there. First I thought it's because I use a CustomRenderer, but even the standard Editor shows the same behaviour.
Any Idea why this could be?

This is my Xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="QuoteMyDay.EntryPage"
             xmlns:TBGUI="clr-namespace:TBGUI;assembly=TBGUI"
             xmlns:svg="clr-namespace:XamSvg.XamForms;assembly=XamSvg.XamForms"
             xmlns:local="clr-namespace:QuoteMyDay.Model;assembly=QuoteMyDay"
             BackgroundColor="#11CCBC">

  <ContentPage.Content>
    <StackLayout VerticalOptions="FillAndExpand">
      <RelativeLayout VerticalOptions="Start" HorizontalOptions="FillAndExpand">

        <TBGUI:ExtendedLabel LineSpacing="0.7" TextColor="White" FontSize="40" TranslationX="30"
             FontFamily="Alegreya-Regular.ttf"
             RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=200.0}"
             RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=10.0}"
                                     >what's&#x0a;up&#x0a;today:</TBGUI:ExtendedLabel>

        <TBGUI:ExtendedLabel TextColor="White"  HeightRequest="300"
             FontSize="500" FontFamily="Alegreya-Regular.ttf"
             RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Constant=10.0}"
             RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Constant=-130.0}">

          &#x201D;
        </TBGUI:ExtendedLabel>
      </RelativeLayout>

      <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand">
        <Frame Padding="10,20,10,30" VerticalOptions="FillAndExpand">
          <Editor x:Name="Quote" FontFamily="Alegreya-Italic.ttf"
                                 TextColor="White" FontSize="40" VerticalOptions="Fill" TextChanged="OnTextChanged"/>
          <!--          <TBGUI:ExtendedEditor x:Name="Quote" FontFamily="Alegreya-Italic.ttf"
                                LineSpacing="0.7" TextColor="White" FontSize="40" VerticalOptions="Fill" TextChanged="OnTextChanged"/>-->
        </Frame>
          <svg:SvgImage  x:Name="Save" Svg="res:Images.checkmark" HorizontalOptions="CenterAndExpand" VerticalOptions="Fill" HeightRequest="35" Clicked="Save_OnClicked"
            ColorMapping="ff000000=ffaafaf3" ColorMappingSelected="00000000=ff000000;ffffff=00ff00" />
        <BoxView VerticalOptions="End" HeightRequest="10"/>
      </StackLayout>
    </StackLayout>

Is there any way to include the list items with just Xaml code and not by binding?

$
0
0

<?xml version="1.0" encoding="utf-8" ?>


<ListView.ItemTemplate>
?? How to include using Xaml code so that i can have some name to each cell to ease the navigation ??
</ListView.ItemTemplate>

Just ignore, I can't delete it

$
0
0

Found the reason was something completely else

Access Contact Name by No

$
0
0

Is it possible to access Contact Name by Contact No using xamarin.

Can you use Acr.UserDialogs in OnAppearing()?

$
0
0

I would like to display a progress dialog while waiting for a screen to display. Unfortunately, when I do this I don't see it show up. How can I resolve this?

Multiple check boxs in Grid

$
0
0

Hi,

I want to show list of multiple check boxes in my grid and when i click on submit button i need to get the values for all selected checkboxes values.

Exif data from photo

$
0
0

I'm looking for a way to extract the Exif data (specifically, gps coordinates where photo was taken, when available) from images on the phone, both iOS and Android.

XLabs Media Picker doesn't provide this information, and neither does the Xamarin Media Picker plug-in. None of the meta data for an image is set with either of these solutions. Has anybody implemented a way to get this information from an image on the phone?

ListView ItemsSource Binding in XAML Problem

$
0
0

I have a pretty simple Xamarin Forms projects going right now with a ListView on the Content Page. I've got xaml which looks like this.

<ListView x:Name="SupplyLevels" Grid.Row="4" >
  <ListView.ItemTemplate>
    <DataTemplate>
      <ImageCell ImageSource="{Binding SupplyImageFile}" Text="{Binding SupplyName}" />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

In the code-behind I have these declarations.

    private ObservableCollection<SupplyInfo> _supplies = new ObservableCollection<SupplyInfo>();

    public ObservableCollection<SupplyInfo> Supplies
    {
        get { return _supplies; }
    }

Doing this in the OnAppearing() method works fine.

        SupplyLevels.ItemsSource = Supplies;

But NOT doing that and doing this in the XAML doesn't work.

<ListView x:Name="SupplyLevels" Grid.Row="4" ItemsSource="{Binding Supplies}" >
  <ListView.ItemTemplate>
    <DataTemplate>
      <ImageCell ImageSource="{Binding SupplyImageFile}" Text="{Binding SupplyName}" />
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

Why is that?

Thanks


How to stop main thread till the downloading of file completed ?

$
0
0

I want to download a file for which i'm using dependency service to download the file.

Using webclient for downloading file in Droid project.

Suggest me how to do?

How to check current Page is navigated?

$
0
0

If there is a lot of page, some time I want to check current page is navigated or not in the page, Is there any property to check it? Thank you

Custom Renderer Signature Pad

$
0
0

Hello,

I am tring to get a Xamarin signature pad to render in a tabbed page in Xamarin Forms projects. I am using a custom renderer and

I tried this code and nothing rendered...

public class SignaturePadRenderer : PageRenderer
{

    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null || Element == null)
        {
            return;
        }


        var signature = new SignaturePadView(this.Context);




        AddView(signature, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));

    }


}

I then tried ...

public class SignaturePadRenderer : PageRenderer
{

    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null || Element == null)
        {
            return;
        }


        var signature = new SignaturePadView(this.Context);

        var activity = this.Context as Activity;



        activity.AddContentView(signature, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));


    }

}

}

This worked and rendered the signature page But now every tab has the signature pad...

Please help...

Thanks

HttpClient for downloading data from url?

$
0
0

I need to download a image from url and show it over UI. How to do that by using HttpClient? @JohnMiller any suggestions..

Why is CustomTabbedPageRenderer not navigating to or displaying page it is supposed to be rendering

$
0
0

So know how to set up a custom renderer (only partially apparently) with an OnElementChanged method and I have read this (post:http://forums.xamarin.com/discussion/17654/tabbedpage-icons-not-visible-android) to try to get icons in the tabs.

The following method gets hit, but it never displays the page afterwards.

    protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);
            _activity = this.Context as Activity;
        }

Anyone have any ideas?

Viewing all 58056 articles
Browse latest View live