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

Error inflating class android.support.v7.widget.Toolbar after updaring to v7.AppCompat Version 23.3

$
0
0

I am creating a Xamarin Forms Project and using android.support.v7.widget.Toolbar with FormsAppCompatActivity. The code I'm posting below was working with Xamarin.Android.Support.v7.AppCompat Version: 23.0.1.3

But after I upgraded to 23.3.0 this has started throwing Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.toolbar exception.

Here is my code for MainActivity

[Activity(Label = "AppMob.Client", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

        protected override void OnCreate(Bundle bundle)
        {
            FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
            FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            Xamarin.FormsMaps.Init(this,bundle);                        
            GoogleAnalyticsHelper.GetGASInstance().Initialize_NativeGAS(Application.Context);  //For GA initialization
            LoadApplication(new App());
        }
}

This is my code for Resource.Layout.toolbar

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />

Need to detect position and dimension of an object (Basically a sticker) on an image .

$
0
0

Hi Geeks ,

I need to find a sticker on an image and calculate its position and the dimension of this object .

What is IsVisible=False literally comparing with WPF Visibility Hidden or Collapsed?

Override Entry properties in iOS

$
0
0

I able to change the property of existing entry using below function in android, by doing this i was able to change the font size and font family of all entry used without creating a subClass like MyEntry , CustomEntry etc etc:

****[assembly: ExportRenderer(typeof(Entry), typeof(xx.Droid.Controls.EntryRenderer))]
namespace xx.Droid.Controls
{
public class EntryRenderer : Xamarin.Forms.Platform.Android.EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);

        if (e.OldElement != null || e.NewElement != null)
        {

            Control.TextSize = 12f;
            Control.Typeface = Typeface.CreateFromAsset(Context.Assets, "OpenSans-Regular.ttf");
        }

    }
}

}****

But when i try to do the same for iOS. it is not working:

**[assembly: ExportRenderer(typeof(Entry), typeof(xx..iOS.Controls.EntryRenderer))]
namespace Mobilefacilities.iOS.Controls
{
public class EntryRenderer : ViewRenderer<Entry, UITextField>
{
public EntryRenderer()
{

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

        if (e.OldElement != null || e.NewElement != null)
        {

            Control.Font = UIFont.FromName("OpenSans-Regular", 12f);
            Control.TextColor = UIColor.FromRGB(127,127,127);



        }

    }
}

}**

Please help if it is even possible in iOS, if yes what is that i am not doing correct?. Thanks in advance!!

How to get selected item in listview using longpress with mr.gestures?

$
0
0

Hi!

I'm try to get an selected item in listview using longpress with mr.gestures but I'm not getting any success.

Could someone give me an example of using with MVVM?

Regards.

Placing a control using x,y floating on top of a grid

$
0
0

Hi,

I have this third party control I have to float in front of a grid populated with several controls (labels, edits, etc). The requirement is to have it stay at a certain distance from the left and bottom of the screen. These values change when the user rotates the screen. This is all in Xamarin Forms but I am only testing Android for now.

I am overriding OnSizeAllocated to get the width and height and from those values I calculate a point where the control should be. The problem is that the control seems to be on a different coordinate system from the sizes passed on to OnSizeAllocated making it impossible to get a proper calculation. I wonder if there is some documentation that explains how to go from one system to the other (or am I missing the point completely).

I cannot put the control in the grid because of a bug in the control. I need to set its x and y position.

Thanks!

Overlay transparent StackLayout on OpenGLView?

$
0
0

Has anyone tried the above? I have a complex 3d model rendering in an OpenGLView. I'd like to place a StackLayout on top of the openglview. Will this approach work at all?

ControlTemplate Triggers

$
0
0

I'm trying to use Triggers in my ControlTemplate but the control is not updating. I have tried using both basic property Trigger and DataTrigger. Has anyone used Triggers in a ControlTemplate in Xamarin based on a Parent / TemplatedParent custom control's BindableProperty? I have tried every variation of binding and Property setting I can think of. I'm starting to think that what I'm trying to do will just not work.

Any insight appreciated. Thanks!

    <ControlTemplate x:Key="LabeledFieldTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <!--Default is "Above"-->
            <Label x:Name="LabelText"
                               Grid.Row="0"
                               Grid.Column="1"
                               FontSize="{TemplateBinding LabelFontSize}"
                               TextColor="MediumVioletRed"
                               Text="{TemplateBinding Label}">
                <Label.Triggers>
                    <Trigger TargetType="Label" Property="controls:LabeledField.LabelPosition" Value="None">
                        <Setter Property="IsVisible" Value="False" />
                    </Trigger>

                    <Trigger TargetType="Label" Property="controls:LabeledField.LabelPosition" Value="Right">
                        <Setter Property="Grid.Column" Value="1"/>
                        <Setter Property="Grid.Row" Value="0"/>
                        <Setter Property="Label.TextColor" Value="Purple"/>
                        <Setter Property="VerticalOptions" Value="Start" />
                        <Setter Property="WidthRequest" Value="{TemplateBinding LabelColumnWidth}" />
                        <Setter Property="Margin" Value="{TemplateBinding LabelPaddingWhenRight}" />
                    </Trigger>


                    <DataTrigger TargetType="Label" Binding="{TemplateBinding BindingContext.LabelPosition}" Value="Left">
                        <Setter Property="Grid.Column" Value="0"/>
                        <Setter Property="Grid.Row" Value="0"/>
                        <Setter Property="Label.TextColor" Value="Green"/>
                        <Setter Property="VerticalOptions" Value="Start" />
                        <Setter Property="WidthRequest" Value="{TemplateBinding LabelColumnWidth}" />
                        <Setter Property="Margin" Value="{TemplateBinding LabelPaddingWhenLeft}" />
                    </DataTrigger>


                    <DataTrigger TargetType="Label" Binding="{Binding LabelPosition}" Value="Above">
                        <Setter Property="Grid.Column" Value="0"/>
                        <Setter Property="Grid.Row" Value="0"/>
                        <Setter Property="Label.TextColor" Value="Orange"/>
                        <Setter Property="VerticalOptions" Value="End" />
                        <Setter Property="HeightRequest" Value="-1" />
                        <Setter Property="WidthRequest" Value="{Binding Width, Source={x:Reference Content}}" />
                        <Setter Property="Margin" Value="{TemplateBinding LabelPaddingWhenAbove}" />
                    </DataTrigger>


                    <DataTrigger TargetType="Label" Binding="{TemplateBinding Parent.LabelPosition}" Value="Below">
                        <Setter Property="Grid.Column" Value="0"/>
                        <Setter Property="Grid.Row" Value="1"/>
                        <Setter Property="Label.TextColor" Value="Blue"/>
                        <Setter Property="VerticalOptions" Value="End" />
                        <Setter Property="HeightRequest" Value="-1" />
                        <Setter Property="WidthRequest" Value="{Binding Width, Source={x:Reference Content}}" />
                        <Setter Property="Margin" Value="{TemplateBinding LabelPaddingWhenBelow}" />
                    </DataTrigger>
                </Label.Triggers>
            </Label>

            <ContentPresenter x:Name="Content"
                                          Grid.Row="1"
                                          Grid.Column="0"
                                          VerticalOptions="CenterAndExpand">
                <ContentPresenter.Triggers>
                    <DataTrigger TargetType="ContentPresenter" Binding="{TemplateBinding Parent.LabelPosition}" Value="Right">
                        <Setter Property="Grid.Column" Value="0"/>
                        <Setter Property="Grid.Row" Value="0"/>
                    </DataTrigger>

                    <DataTrigger TargetType="ContentPresenter" Binding="{TemplateBinding Parent.LabelPosition}" Value="Left">
                        <Setter Property="Grid.Column" Value="1"/>
                        <Setter Property="Grid.Row" Value="0"/>
                    </DataTrigger>

                    <DataTrigger TargetType="ContentPresenter" Binding="{TemplateBinding Parent.LabelPosition}" Value="Above">
                        <Setter Property="Grid.Column" Value="0"/>
                        <Setter Property="Grid.Row" Value="1"/>
                    </DataTrigger>

                    <DataTrigger TargetType="ContentPresenter" Binding="{TemplateBinding Parent.LabelPosition}" Value="Below">
                        <Setter Property="Grid.Column" Value="0"/>
                        <Setter Property="Grid.Row" Value="0"/>
                    </DataTrigger>
                </ContentPresenter.Triggers>
            </ContentPresenter>
        </Grid>
    </ControlTemplate>

Here is a snippet of code that defines the LabelPosition property on the LabeledField class

           public static readonly BindableProperty LabelPositionProperty = BindableProperty.Create(
                "LabelPosition",
                typeof(LabelPosition),
                typeof(LabeledField),
                LabelPosition.Right,
                propertyChanged: UpdateLayout);
        
            public LabelPosition LabelPosition
            {
                get => (LabelPosition)GetValue(LabelPositionProperty);
                set => SetValue(LabelPositionProperty, LabelPosition);
            }
        
            public static LabelPosition GetLabelPosition(BindableObject element)
            {
                return (LabelPosition)element.GetValue(LabelColumnWidthProperty);
            }
        
            public static void SetLabelPosition(BindableObject element, LabelPosition value)
            {
                element.SetValue(LabelPositionProperty, value);
            }
        
            private static void UpdateLayout(BindableObject bindable, object oldvalue, object newvalue)
            {
                var labeledField = bindable as LabeledField;
                //Calling this method will invalidate the measure and triggers a new layout cycle.
                //labeledField?.InvalidateLayout();
        
                //labeledField?.UpdateChildrenLayout();
                labeledField?.ForceLayout();
            }

Custom renderer for Android for Tabbed Page

$
0
0

I need Tabbed page's custom renderer for Android. I found the working solution for IOS but dont know how to translate it for Android

using AdvancedForms.iOS;
using System;
using System.Collections.Generic;
using System.Text;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))]
namespace AdvancedForms.iOS
{
public class TabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);

        TabBar.TintColor = UIColor.Red;
        TabBar.BarTintColor = UIColor.Black;
        TabBar.BackgroundColor = UIColor.Gray;
    }
}

}

How to achieve a Rotate Gesture in Xamarin Forms?

$
0
0

I have requirement, where in i need to rotate the view(Drawing Component, Boxview, Label and etc). There is possibility to do by using Rotate Gesture. I am in need of How to achieve a rotate gesture and How to find the rotation angle by using rotate gesture? Please anyone suggest me how to achieve these two functionality by using xamarin forms

Add shadow to a Label

$
0
0

Hi guys, I would like to add drop shadow to a Label. This label is overlapped in the Page, like an always visible control that opens a filtering page.

Please find a gif attached with my screen:

My app

Here's my XAML:

    <!-- **** Filter button **** -->
    <Label
        Margin="0,0,10,10"
        WidthRequest="50"
        HeightRequest="50"
        HorizontalOptions="End"
        VerticalOptions="End"
        HorizontalTextAlignment="Center"
        VerticalTextAlignment="Center"
        FontSize="30"   
        Style="{DynamicResource FilterAction}"
        Text="&#xf0b0;"
        BackgroundColor="{StaticResource ComplementColor}"
        FontFamily="{x:Static artina:FontAwesome.FontName}"
        TextColor="White">
        <Label.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding btn_open_filter_businesses_click}" />
        </Label.GestureRecognizers>
    </Label>

    <templates:Badge 

        BadgeText="{Binding number_of_filters_selected}" 
        BadgeTextColor="White"  
        BadgeBackgroundColor="#1DBDFF"
        HorizontalOptions="End"
        VerticalOptions="End"
        TranslationX="-4"
        TranslationY="-4"
        IsVisible="{Binding number_of_filters_selected, Converter={StaticResource filterVis}"
        x:Name="filtersCountBagde">
        <templates:Badge.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding btn_open_filter_businesses_click}" />
        </templates:Badge.GestureRecognizers>
    </templates:Badge>

I would like something like Gmail, find the example below:

Example

Any help would be appreciated.

[Prism] Why am I not able to wrap my page inside NavigationPage in Prism?

$
0
0

So I'm trying to run this sample from Prism. I'm not able to wrap the MainPage inside NavigationPage.

NavigationService.NavigateAsync("MainPage"); works for me but not NavigationService.NavigateAsync("NavigationPage/MainPage");

Here is the exception I'm getting,

Foundation.MonoTouchException has been thrown Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch

Note: I have updated all packages in the project.

tableview viewcell problem

$
0
0

I have a problem with my viewcell with StackLayout. I want to change the backgroundcolor during runtime. The problem i have is that when the user tap on the viewcell. The background color only take effect when you scroll the tableview. Can someone please help with this problem

Azure push notifications

$
0
0
Doed anyone know how to use conditionals to trigger a push notification with azure notification hub? For example, if CurrentTime == UserSpecifiedTime, trigger push notification

How to bind data into External Maps

$
0
0

Hi,
I would like to know if it is possible to bind data into External Maps plugin. I have address data that coming via WebAPI.

CrossExternalMaps.Current.NavigateTo("Space Needle", 47.6204, -122.3491);
Here, I want to bind name, longitude, and latitude from Model/ViewModel. Could you please help me to accomplish this?

Thank you!


On iOS, can I set the StatusBar text color independently of the NavigationPage.BarTextColor?

$
0
0

I have a Xamarin.Forms app I've been working on and I can't seem to set the colors as I'd like on iOS. I'm using a NavigationPage as the main page of the app with a normal content page inside of it. Forms v1.5.0.6446

Since I'm using a dark NavigationPage.BarBackgroundColor (Navy Blue in this example), I need the StatusBar text color to be White (or LightContent style), and the BarTextColor to be a different color (Yellow in this example). I've attached an image to illustrate what I need.

The issue I'm running into is that the NavigationPage.BarTextColor controls both the BarTextColor and the StatusBar text color. There must be some logic built into Xamarin.Forms that is doing this. What I've found is that if I set the BarTextColor to some light colors like Silver and Pink, then the StatusBar text will be white. But setting the BarTextColor to "darker" colors, like Yellow, or even Aqua (!), will result in StatusBar text that is Black. It appears they've made some decisions for me, and I don't like that :)

This setting in the Info.Plist file appears to be critical. Without it, I couldn't get the StatusBar text color to be white. No matter what I did, it was always black:
View controller-based status bar appearance: No

None the forum posts or examples I've seen do what I need specifically; they're happy setting both text colors to white, while I need them to differ.

I've tried setting the StatusBarStyle directly in my iOS AppDelegate like this:
UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);
But this doesn't have any effect.

I've also tried setting the Status Bar Style in the Info.plist file - no effect either.

I created a small sample project that I'll attach as well. I'd appreciate any ideas. Thanks!

Azure - Error Handling during PullAsync and PushAsync process

$
0
0

I am new to Azure. We are planning to implement it in our app. Before that I need to know all the possibilities on how to Handling error in Azure DURING PUSH AND PULL SERVICE between local database to cloud.

How can I identify whether the Push and Pull process done its work correctly or not.

How can I push or pull again, If error occurs.

Thank you all in advance.

Xamarin App for Windows, iOS, Android and Mac

$
0
0

Hi!
We have started using Xamarin.Forms for a Trial Project. Now a new bigger and more substentiall Project is coming up.

My plan would be to start the new (business critical) app with iOS und Android and later on generate also an UWP and MacOS Version.

To push through, it would be easier to have a reference app, which at least runs under iOS, Android and UWP. Is there a known App, which could be used therefore? The MSN News App is now in beta with Xamarin.Forms, but as I understood, the UWP Version is still "normal" and only Shares Code with iOS and Android Xamarin.forms. Is this correct? Are there other reference Projects?

Thanks in advance
Wolfgang

Frame in android devices is not working entire view is gone

$
0
0

I am not able to see the views when put inside the frame whether it is inside listview or simple view

ListView update cell display

$
0
0

I change the size of cells using slider, but Cells of listView are not updating
how to do it?

    private void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
            {
                lstView.RowHeight = (int)e.NewValue;
            }
Viewing all 58056 articles
Browse latest View live