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

how to make our WebView only show youtube video instead of entire page of youtube

$
0
0

i have webview in list and i'm showing youtube videos as per list of article have in my app but user can able to see whole entire page of youtube and they can search another videos too. i just wanted the they should able to see just youtube video rather than entire page?
please help


MapRenderer OnMapReady event equivalent for iOS ?

$
0
0

I need an equivalent event for an iOS renderer:

public class MyMapRenderer : Xamarin.Forms.Maps.Android.MapRenderer
{
    ...

    protected override void OnMapReady(GoogleMap map)
    {
        base.OnMapReady(map);

        // need to do things here
    }

    ...
}

Thanks

ListView gets refreshed only after I scroll after updating an item

$
0
0

Hello,

I am creating a shopping cart app and I am stuck in between with Listview refresh. I have a view cell in my list view and it has a Image button. When I click on the image button based on the model parameter(bool) I am replacing the image. After I update the model property, my listview is not getting refreshed automatically. Refresh happens only after I scroll the ListView.

Is there anything I am missing in below code?

Code: View cell in listview-

                         <ImageButton

                                            Grid.Row="0"

                                            Grid.Column="1"

                                        Margin="5,10,10,5"

                                        Aspect="AspectFit"

                                        BackgroundColor="Transparent"

                                        Command="{Binding Path=BindingContext.CartCommand, Source={x:Reference product}}"

                                        CommandParameter="{Binding .}"

                                        HorizontalOptions="End"

                                        Source="{Binding WishListImageIcon}"

                                        VerticalOptions="Center" />

View model:

public ICommand CartCommand { get; private set; }

private void UpdateCartImage(Electronics electronic)

        {

            if (electronic.WishList)

            {

                electronic.WishList = false;



            }

            else

            {

                electronic.WishList = true;



            }



            int pos = ElectronicList.IndexOf(electronic);

            ElectronicList.RemoveAt(pos);

            ElectronicList.Add(electronic);

        }

Model:

public bool WishList

        {

            get { return _wishList; }

            set { SetValue(ref _wishList, value); }

        }



        public string WishListImageIcon

        {

            get { return WishList ? "icon_wish_click.png" : "icon_wish_unclick.png"; }



        }

I am new to Xamarin. Kindly help me to resolve the issue.

Thanks,
Prasanna

Error while parsing timestamp in GCM

$
0
0

07-18 17:22:37.347 W/FirebaseMessaging(18679): Error while parsing timestamp in GCM event
07-18 17:22:37.347 W/FirebaseMessaging(18679): java.lang.NumberFormatException: s == null
07-18 17:22:37.347 W/FirebaseMessaging(18679): at java.lang.Integer.parseInt(Integer.java:577)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at java.lang.Integer.valueOf(Integer.java:801)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.messaging.zzd.zzb(Unknown Source:60)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.messaging.zzd.zzh(Unknown Source:84)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.messaging.FirebaseMessagingService.zzo(Unknown Source:35)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.iid.zzf.zza(Unknown Source:38)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.iid.zzh.zzcfv(Unknown Source:80)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.iid.zzh.zza(Unknown Source:29)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.google.firebase.iid.FirebaseInstanceIdInternalReceiver.onReceive(Unknown Source:41)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3380)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at android.app.ActivityThread.access$1200(ActivityThread.java:200)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1662)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at android.os.Handler.dispatchMessage(Handler.java:106)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at android.os.Looper.loop(Looper.java:193)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at android.app.ActivityThread.main(ActivityThread.java:6692)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at java.lang.reflect.Method.invoke(Native Method)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
07-18 17:22:37.347 W/FirebaseMessaging(18679): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
07-18 17:22:37.349 W/FirebaseMessaging(18679): Unable to log event: analytics library is missing

Custom Control With ICommand Property Not Working

$
0
0

Hi there!

I created a simple custom control (Inherited from ContentView) for learing purposes. The control has two custom properties: Text and Command. When I use this custom control with a page test, the property Text works, but Command doesn't.

What is wrong with my code?

Many thank for any kind of help.

This is my custom control (MyCustomControl.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="ReusableUserControls.MyCustomControl">

  <ContentView.Content>

    <StackLayout>

      <Entry x:Name="myEntry" Placeholder="enter something" />

      <Button x:Name="myButton" Text="Ok" />

    </StackLayout>

  </ContentView.Content>
</ContentView>>

With the following code behind (MyCustomControl.xaml.cs):

using System;
using System.Windows.Input;
using Xamarin.Forms;

namespace ReusableUserControls
{
    public partial class MyCustomControl : ContentView
    {
        public MyCustomControl()
        {
            InitializeComponent();
            //
            this.myButton.Clicked += (object sender, EventArgs e) =>
            {
                Execute(Command);
            };

            this.myEntry.TextChanged += (object sender, TextChangedEventArgs e) =>
            {
                Text = e.NewTextValue;
            };
        }

        public static readonly BindableProperty TextProperty =
            BindableProperty.Create(nameof(Text),
                                    typeof(string),
                                    typeof(MyCustomControl),
                                    "",
                                    BindingMode.TwoWay,
                                    propertyChanged: (BindableObject bindable, object oldValue, object newValue) =>
                                    {
                                        var thisView = bindable as MyCustomControl;
                                        if (thisView == null) return;
                                        //
                                        thisView.Text = (string)newValue;
                                    });
        //
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); this.myEntry.Text = value; }
        }

        public static readonly BindableProperty CommandProperty =
            BindableProperty.Create(nameof(Command),
                                    typeof(ICommand),
                                    typeof(MyCustomControl),
                                    null);
        //
        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        // Helper method for invoking commands safely
        public static void Execute(ICommand command)
        {
            if (command == null) return;
            if (command.CanExecute(null))
            {
                command.Execute(null);
            }
        }

    }
}

To test MyCustomControl, I created the following page: (CustomControlTestPage.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"
             xmlns:local="clr-namespace:ReusableUserControls;assembly=ReusableUserControls"
             x:Class="ReusableUserControls.CustomControlTestPage">

  <ContentPage.Padding>
    <OnPlatform x:TypeArguments="Thickness" iOS="10,20,10,10" Android="10" WinPhone="10" />
  </ContentPage.Padding>

  <ContentPage.BindingContext>
    <local:MyCustomControlViewModel />
  </ContentPage.BindingContext>

  <StackLayout Spacing="10">

    <!-- THE COMMAND ASSIGN TO CUSTOM CONTROL DOESN'T WORK -->
    <local:MyCustomControl Text="{Binding Nome}" Command="{Binding ProcessCommmand}" />

    <!-- THE COMMAND ASSIGN TO BUTTON'S PAGE WORKS -->
    <Button Text="This button works" Command="{Binding ProcessCommand}" />

  </StackLayout>

</ContentPage>

Here is the ViewModel class (MyCustomControlViewModel.cs):

namespace ReusableUserControls
{
    public class MyCustomControlViewModel : ViewModelBase
    {

        string _nome;
        public string Nome
        {
            set { SetProperty(ref _nome, value); }
            get { return _nome; }
        }

        public ICommand ProcessCommand { get; set; }

        public MyCustomControlViewModel()
        {
            ProcessCommand = new Command(ProcessCommandExecute);
            Nome = "1, 2, 3 testin...";
        }

        private void ProcessCommandExecute(object obj)
        {
            // Just to test the command binding
            var a = 1;
        }
    }
}

why is the button within the listview repeating

$
0
0

l have a list with an item source and a button.. the button is not bounded to the list data source but it repeats for as many itemsource that exists in the list. see code below and image to illustrate better

<ListView x:Name="listView"   >
    <ListView.ItemsSource>
         <x:Array Type="{x:Type local:MasterPageItem}">
            <local:MasterPageItem Title="Sign In" ![](https://us.v-cdn.net/5019960/uploads/editor/i3/yvn85vuyq4ql.png "")

                    TargetType="{x:Type local:LoginPage}" 
                    IconSource="profile.png"/> 
             <local:MasterPageItem Title="Sign In" 
                    TargetType="{x:Type local:LoginPage}" 
                    IconSource="profile.png"/>
              <local:MasterPageItem Title="Sign In" 
                    TargetType="{x:Type local:LoginPage}" 
                    IconSource="profile.png"/>   

         </x:Array>
    </ListView.ItemsSource>
    <ListView.ItemTemplate>  
        <DataTemplate>
            <ViewCell>
            <ViewCell.View>         
             <Button Text="test" BackgroundColor="Red"
                     CornerRadius="0"/>


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

I cant seem to deploy a local build on my iPhone with VS 2019

$
0
0

I recently downloaded and installed Visual Studio 2019 to run my Xamarin Forms project. I added my apple user to the Visual Studio options and downloaded all the provision profiles. I also right clicked properties on the iOS project and verified that my apple cert and profile show. Then I connect to my mac host and attempt to deploy to my iPhone (which worked before)...and the error I get is "Could not find any available provisioning profiles for iOS". I triple checked and made sure my device, cert and provision are all connected and are all good and they are. Is anyone else having issues with this on Visual Studio 2019?

How to pass date through body in put

$
0
0

public IHttpActionResult PutUpdateDate(string name, int no, [FromBody]DateTime date)
{
//some code here
}

How to pass date through body.


Why my pins on android are lost ?

$
0
0
Hi all,
On ios my pins are correctly set.
But on android (with google maps) ou pins are drugs like this :

Embedding a custom Content View in another xaml - Exception: System.InvalidCastException: Specified

$
0
0

Hi,
I've created my own C# content view class with XAML using the "Add Item" menu option in Visual Studio.

I try to embed this content view into a the xaml of a Page class and at runtime the InitializeComponent() method in my ContentView's View.g.cs file throws
and exception "Exception: System.InvalidCastException: Specified" on the following line of code:

    private void InitializeComponent() {
        global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(TextFieldViewV1));          <<---- THIS THROWS EXCEPTION
        xxamFieldValueEntry = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Xamarin.Forms.Entry>(this, "xxamFieldValueEntry");
    }

The XAML for my Content View "TextFieldViewV1" is trivial:


<ContentView.Content>



</ContentView.Content>

I include the namespace of the content view in the Xaml of my test page and the project compiles without errors.

Possible to update Label.Text *before* display?

$
0
0

I have a view that is essentially a popup window. The view "opens" and "closes" simply by toggling IsVisible. The view contains several labels whose contents change each time the view becomes visible. I am updating the Label.Text fields before setting IsVisible on the parent view. However, there is a noticeable flash after the view becomes visible as the labels are still changing to their new text values. Is there anyway to avoid this and ensure that the new values are fully updated before the view becomes visible?

Thanks in advance for any input!

Download new Xamarin CSS at runtime

$
0
0

I see that Xamarin using CSS to style the pages uses an EmbeddedResource.

I want a default CSS file and then download a file at Load time to style the app based on Client CSS. Is it possible either to extend or override the Embedded CSS file or can I do something crazy to embed another resource at runtime?

After Updating to X.F4.1 iOS and UWP crashes (CrossMedia Plug In?)

$
0
0

Hello Guys,

I updated XF to 4.1. I am using CrossMedia to pick Images. On iOS i can select an Image and the app crashes.
Getting this Message:
2019-07-18 23:03:45.191 Retailer.iOS[599:127128] Unable to get metadata: System.ArgumentNullException: Value cannot be null.
Parameter name: asset
at Photos.PHImageManager.RequestImageData (Photos.PHAsset asset, Photos.PHImageRequestOptions options, Photos.PHImageDataHandler handler) [0x00087] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Photos/PHImageManager.g.cs:170
at Plugin.Media.PhotoLibraryAccess.GetPhotoLibraryMetadata (Foundation.NSUrl url) [0x0004c] in <390f35b1db5e43b894d803204ceef8a9>:0
at Plugin.Media.MediaPickerDelegate.GetPictureMediaFile (Foundation.NSDictionary info) [0x00319] in <390f35b1db5e43b894d803204ceef8a9>:0

Die App wurde beendet.

Native Crash Reporting

Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries

used by your application.

=================================================================

Basic Fault Adddress Reporting

Memory around native instruction pointer (0x1abcacdd0):0x1abcacdc0 fd 7b c1 a8 c0 03 5f d6 30 41 80 d2 01 10 00 d4 .{.....0A......
0x1abcacdd0 c3 00 00 54 fd 7b bf a9 fd 03 00 91 18 db ff 97 ...T.{..........
0x1abcacde0 bf 03 00 91 fd 7b c1 a8 c0 03 5f d6 d0 03 80 d2 .....{....
.....
0x1abcacdf0 01 10 00 d4 c3 00 00 54 fd 7b bf a9 fd 03 00 91 .......T.{......

=================================================================

Native stacktrace:

=============================================
0x102b49c8c - /var/containers/Bundle/Application/BC1675E5-974C-458E-BDB6-95D0E1258C4D/Retailer.iOS.app/Retailer.iOS : (null)
0x102b409c8 - /var/containers/Bundle/Application/BC1675E5-974C-458E-BDB6-95D0E1258C4D/Retailer.iOS.app/Retailer.iOS : (null)
0x1abd219ec - /usr/lib/system/libsystem_platform.dylib :
0x1abca6924 - /usr/lib/system/libsystem_kernel.dylib :
0x1abca6954 - /usr/lib/system/libsystem_kernel.dylib : fcntl
0x1aee88b50 - /System/Library/PrivateFrameworks/TCC.framework/TCC :
0x1aee88a90 - /System/Library/PrivateFrameworks/TCC.framework/TCC :
0x1aee8c92c - /System/Library/PrivateFrameworks/TCC.framework/TCC :
0x1abd74e88 - /usr/lib/system/libxpc.dylib :
0x1abd6859c - /usr/lib/system/libxpc.dylib :
0x1abb51854 - /usr/lib/system/libdispatch.dylib :
0x1abb0ae50 - /usr/lib/system/libdispatch.dylib :
0x1abb02dfc - /usr/lib/system/libdispatch.dylib :

~~~~
On UWP the app does not compile:

Fehler Die Ladung enthält mehrere Dateien mit dem gleichen Zielpfad "e_sqlite3.dll". Quelldateien:
C:\Users\agredo.nuget\packages\sqlitepclraw.lib.e_sqlite3.v140\1.1.11\runtimes\win10-x64\native\e_sqlite3.dll
C:\Users\agredo.nuget\packages\sqlitepclraw.lib.e_sqlite3.v140\1.1.11\runtimes\win10-x86\native\e_sqlite3.dl

Some times this error does not Show up. The the app builds but crashes with the info KERNELBASE.dll error in Event Viewer.

Maybe you can help me.

Thank you

PreBuild event to remove xaml files in main project

$
0
0

I have a group of xaml files in a Shared Project. At build time, I want the xaml files to replace the files in the Main Core project for Xam Forms.

Basically, I am trying to override xaml files. I'm using a viewModel, so I only need to change the xaml. If a client needs a different UI for a screen I'd like to just replace the xaml with a Shared Project.

Any Ideas?

How can I set and get a selected value in my custom picker? The value is not changeable

$
0
0

How can I get the selected item of my custom picker? It always goes back to the initial state
I tried in several ways and I only had to question.

 public class MyDelegate : UIPickerViewDelegate
    {
        List<string> sourceList = new List<string>();
        public MyDelegate(List<string> list)
        {
            sourceList = list;
        }
        public override void Selected(UIPickerView pickerView, nint row, nint component)
        {
            UILabel label = new UILabel();
            label.Text = sourceList[(int)row];
        }

        public override UIView GetView(UIPickerView pickerView, nint row, nint component, UIView view)
        {

            try
            {

                UIView contentView = new UIView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, 80));

                UILabel label = new UILabel();
                label.Frame = contentView.Bounds;
                contentView.AddSubview(label);
                label.Text = sourceList[(int)row];
                label.Lines = 4;
                label.TextAlignment = UITextAlignment.Center;
                //Change the label style
                label.Font = UIFont.SystemFontOfSize(20);
                label.LineBreakMode = UILineBreakMode.TailTruncation;
                return contentView;

            }
            catch (Exception ex)
            {

                throw;
            }

            //return base.GetView(pickerView, row, component, view);
        }
        public override nfloat GetRowHeight(UIPickerView pickerView, nint component)
        {
            return 80;
        }
    }
}


   public class CustomPickerRenderer : PickerRenderer
    {
        List<string> itemList = new List<string>();
        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);
            var element = (CustomPicker)this.Element;
            Picker picker = Element;
            //itemList = picker.Items.ToList();       
                UITextField uITextField = new UITextField();
                uITextField = Control;
                UIPickerView uIPickerView = uITextField.InputView as UIPickerView;       

            if (this.Control != null && this.Element != null && !string.IsNullOrEmpty(element.Image))
            {
                var downarrow = UIImage.FromBundle(element.Image);
                Control.RightViewMode = UITextFieldViewMode.Always;
                this.Control.BorderStyle = UITextBorderStyle.None;
                Control.LeftView = new UIKit.UIView(new CGRect(0, 0, 5, 0));
                Control.LeftViewMode = UIKit.UITextFieldViewMode.Always;
                Control.BorderStyle = UITextBorderStyle.None;
                Control.RightView = new UIImageView(downarrow);
            }
        }
    }
}

Xam.Plugins.Notifier: Android Tap in Xamarin.Forms.Shell

$
0
0

Using Xam.Plugins.Notifier for Local Notifications I am able to show a notification in Android. However, when I tap the notification, it reloads the application. Similar to how a remote notification would.

I handle the OnNewIntent() in the MainActivitiy.cs but it never fires.

How do I tap a Local Notification made by Xam.Plugins.Notifier so that OnNewIntent() fires and I can show a Shell item?

    protected async override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        var title = intent.GetStringExtra("title");
        if (title != null)
        {
            await Shell.Current.GoToAsync("Tools/Sales");
        }
    }

How can i make a label fit/ auto size the grid row and column specified for it?

$
0
0

Hi,
I am using Grid layout to try making the app responsive and when i use label and set a font size to it, the label sometimes surpasses the space (grid.row & grid.colum) alocated for it.

Is it possible to make the label always fit the alocated space ?

<Grid RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="3.5*"/>
                <RowDefinition Height="6.5*"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" Grid.Column="0">
                <Image x:Name="imagemNav" Grid.Row="0" Grid.Column="0" Source="{local:ImageResource KiaiDay.Images.navigationImage.png}" Aspect="Fill"
                    HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
                <Grid Padding="20,10,20,0" ColumnSpacing="0" RowSpacing="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="3.5*"/>
                        <RowDefinition Height="4.5*"/>
                        <RowDefinition Height="2*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="6*"/>
                        <ColumnDefinition Width="4*"/>
                    </Grid.ColumnDefinitions>

...
                    <StackLayout Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Spacing="4">
                        <Label Text="Some text" FontSize="50" TextColor="White" FontFamily="{ StaticResource RegularFont}" Margin="20,0,0,0"/>
                        <Label Text="Some other text" FontSize="20" TextColor="White" FontFamily="{ StaticResource LightFont  }" Margin="25,-10,0,0"     
                                    Opacity="0.7"/>
                    </StackLayout>
...
</Grid>

How to change the name of app(In the screen, under the icon)

$
0
0

Hi guys,

I am building an app in Xamarin.Forms. I want to change the name of app, both iOS and Android. I tried to change the information in mainactivity.cs and Androidmanifest. However it is not working. I also don't know how to do it in iOS.

Would you please to help me?

Thank you very much.

Firing method in the View when a property in the ViewModel changes

$
0
0
Hi all,
As the title says I would like to call a method in my View when a property in my ViewModel changes. I was wondering if this is possible to do it by using the INotifyPropertyChanged interface or if I should implement the observer - observable pattern on my own for this particular task.

Practical example: I have a StackLayout in the View and an integer property called number in the ViewModel, I want to call a method in the View which makes sure there are exactly n (where n is the value of number) entries in the StackLayout every time number changes.

Note: number is the output of a calculation in the model and it doesn't have to appear anywhere in the view.

Thanks to everyone in advance.

How to set vertical align icon of the selected tab in a tabbedpage

$
0
0

Hi everyone, the icon of the selected tab aligns top vertically. How to set that alignment to center like others unselected tabs?

I am using FreshMVVM Framework and this is the code:

var masterDetailsMultiple = new MasterDetailPage();
masterDetailsMultiple.Title = "Master";
var menuPage = FreshPageModelResolver.ResolvePageModel();
masterDetailsMultiple.Master = menuPage;

var tabbedNavigation = new FreshTabbedNavigationContainer();
tabbedNavigation.On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
tabbedNavigation.AddTab("", "update2.png", null);
tabbedNavigation.AddTab("", "form2.png", null);
tabbedNavigation.AddTab("", "poll2.png", null);
tabbedNavigation.AddTab("", "star2.png", null);
tabbedNavigation.AddTab("", "ideas2.png", null);

Viewing all 91519 articles
Browse latest View live


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