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

How to bind image source property to a list of strings programmatically?

$
0
0

I have a carouselView with images and i want to bind each image source property to a list of strings inside carouselView .

class Class1
        {
            public List<string> imageURL { get; set; }

            public Class1()
            {
                imageURL = new List<string>()
                {
                    "imgg1.jpg",
                    "imgg10.jpg",
                    "imgg11.jpg",
                };
            }
        } 

public MainPage()
        {
            InitializeComponent();

            Class1 class1 = new Class1();

            CarouselView carouselView = new CarouselView();
            carouselView.BindingContext = class1;
            carouselView.ItemsSource = class1.imageURL;
            carouselView.ItemTemplate = new DataTemplate(() =>
            {
                StackLayout stackLayout = new StackLayout();

                Image image = new Image();
                image.SetBinding(Image.SourceProperty, new Binding());

How to write properly the above SetBinding() function? For the first parameter Image.SourceProperty everything is clear, but for the second not really.

                stackLayout.Children.Add(image);
                return stackLayout;
            });

            s1.Children.Add(carouselView);
        }

BindingSource of control changes when added into a view

$
0
0

I am trying to set a binding in C#. It's initialised once properly and then I get a warning that the control is looking into a different ViewModel for the property and does not update.
Is my view somehow overwriting the binding context of the control that I set in C#, if so how can I tell it to keep i'ts binding?

It does not seem to happen for controls that are binded in xaml

Launching Running app Soon but wish to give free trail before charge of app store

$
0
0

Hi I wish to give my users of my new running app seven days free trail before charging their debit card in ios store. Is this sort of functionality done at the store level or do I also need to code for it in my xamrain forms app.

Also is their any hosted sites like appcentre for your privacy policies screen shots and all.

Is it possible to keep RadioButton as Header of the expandable control Xamarin forms 4.6

$
0
0

Hi,
I'm trying to make a payment method page where if you click on the radio button, the expander body should show the text boxes to add the corresponding details. So I tried this code:

    `<Expander>
                    <Expander.Header>
                        <StackLayout>                                
                            <RadioButton GroupName="PaymentMethod" 
                                 Text="Credit/Debit Card" 
                                 IsChecked="False"/>
                        </StackLayout>
                    </Expander.Header>
                    <Expander.Content>
                        <Grid Padding="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <StackLayout Orientation="Horizontal">
                                    <local:XEntry Style="{StaticResource entry}"                                              
                                          Placeholder="Card Number"
                                          PlaceholderColor="LightGray"
                                          MaxLength="100"/>
                                    <!--Text="{Binding CardNumber}"-->
                                    <local:XEntry Style="{StaticResource entry}"
                                          Placeholder="MM"
                                          PlaceholderColor="LightGray"
                                          Text="{Binding Month}"
                                          MaxLength="2"/>
                                    <Label Text="/"/>
                                    <local:XEntry Style="{StaticResource entry}"
                                          Placeholder="YY"
                                          PlaceholderColor="LightGray"
                                          MaxLength="2"/>
                                    <!--Text="{Binding Year}"-->
                                    <local:XEntry Style="{StaticResource entry}"
                                          Placeholder="CVV"  
                                          PlaceholderColor="LightGray"
                                          MaxLength="3"/>
                                    <!--Text="{Binding CVV}"-->
                                </StackLayout>
                            </Grid>
                            <Grid Grid.Row="1">
                                <StackLayout>
                                    <local:XEntry Style="{StaticResource entry}"                                               
                                          Placeholder="Card Holder Name"
                                          PlaceholderColor="LightGray"
                                          MaxLength="100"/>
                                    <!--Text="{Binding CardHolderName}"-->
                                </StackLayout>
                            </Grid>
                        </Grid>
                    </Expander.Content>                        
             </Expander>`

But the expander was not working.. but when i added a lable in the header

    `<Expander.Header>
                        <StackLayout>
                            <Label  Text="Card Payment"/>
                            <RadioButton GroupName="PaymentMethod" 
                                 Text="{lang:Translate Card}" 
                                 IsChecked="False"/>
                        </StackLayout>
             </Expander.Header>`

It worked..I dont want the lable. Instead, I only need the radio button in the expandable header. Is it possible?

Zoom-function for Cross-platform-project (Android, IOS, UWP)

How to use SVG images for Xamarin.Forms?

$
0
0

It seems it's possible to some extent to use SVG images in some controls, for instance SVG files can be only added as embedded resources when using some of the available NuGet packages out there. Also, at least for ToolbarItem the images need to be stored somewhere in the file system, so I had to create my own SVG rasterizer that saves those images to bitmaps in the cache directory, so those could passed in a FileImageSource to the Icon property in the control ToolbarItem. For, the control Button those images need to be stored in the Resources or drawable directory, so it won't work with the rasterized bitmaps, since those are stored in the cache directory. With all those limitations for trying to use SVG files directly at runtime, I was thinking maybe I could convert all those images to the corresponding JPG or PNG images at build time using some task, but I'm not sure whether that conversion could be done with the current available tools. So, my questions is how to use directly or convert SVG images to use in the common controls in Xamarin.Forms (ToolbarItem, Button, etc)?

X and Y position for button not working

$
0
0

Hello,

I made some updates and since that, the Y position of my buttons are broken.

For example the X and Y of my image button is

X : 211
Y : 0

Wich make no sens.

I think this bug is due to the Shell page.

Any idea to counter this issue ?

I want to give show 2 option as radio button like Gender(Male & Female)

$
0
0

I want to give show 2 option as radio button in a form like Gender(Male & Female). And after select the customer I have to send the checked radio button data into a database column through an API service. How can I do this.
Please Help..Already Thanks.


Unable to use Toast, Activity Indicatior

$
0
0

I have a simple Xamarin Form app with a .net standard project and Android Project. I am facing a problem since day of development is that , I am unable to pull Toast and Activity Indicator on form. I dont know why. I tried almost all major plugins as well.

Here's my login code where I want to see a toast. I have used UserDialogs, Forms.Plugin etc and now using Plugin.Toast.

  protected void BtnLogin_Clicked(object sender, EventArgs e)

        {
            try
            {
                CrossToastPopUp.Current.ShowToastMessage("Message"); // Plugin.Toast package
                var userName = TxtUserName.Text.Trim();
                var password = TxtPassword.Text.Trim();
                userController.DoLogin(userName, password);
            }
            catch (NullReferenceException)
            {
                DisplayAlert("Mobile # and Password, both are required.", "JCAA", "OK");

            }
            catch (Exception ex)
            {
                DisplayAlert(ex.Message, "JCAA", "OK");
                Crashes.TrackError(ex);
            }


        }

How to perform drag and drop in xamarin forms ?

$
0
0

I have multiple list of Images. now i want to drag an image from one list and drop it to other list. and remove that image from previous list and add it to new list.how i can achieve this ?I'm using collection view.Is there Nuget package ?

Hosted PDF is Display inside WebView

$
0
0

Dear All,

I used bellow code to display hosted pdf in webview with the help of google drive url. Its working fine, some times displays white screen (display nothing). Pls help is there any better solution.

var pdfUrl = "http://yourdomain.com/pdffile.pdf";
var googleUrl = "http://drive.google.com/viewerng/viewer?embedded=true&url=";
if(Device.RuntimePlatform == Device.iOS)
{
    webView.Source = pdfUrl;
}
else if(Device.RuntimePlatform == Device.Android)
{
    webView.Source = new UrlWebViewSource() { Url = googleUrl + pdfUrl };
}

Thank you.

Rg.plugins Popup with FreshMVVM callback issue

$
0
0

When the savecommand is triggered I do not get the Event OnOrderItemUpdated fired to the calling PageModel within a Tabbed Page.

//UpdateOrderPageModel Event

public event EventHandler OrderItemUpdated;

    protected virtual void OnOrderItemUpdated(OrderItemEventArgs e)
    {
        EventHandler<OrderItemEventArgs> handler = OrderItemUpdated;
        handler?.Invoke(this, e);
    }

//Save Command in UpdateOrderPageModel Class
var e = new OrderItemEventArgs(new OrderItem());
OnOrderItemUpdated(e);

//Calling Tabbed Page Model

public OrderItem SelectedOrderItem
{
get { return _selectedOrderItem; }
set {
_selectedOrderItem = value;
Task.Run(async () => await PopoUpdatePage());
RaisePropertyChanged(nameof(SelectedOrderItem));
}
}

    private async Task PopoUpdatePage()
    {
        //Private Property UpdateOrder 
        this.UpdateOrder = FreshIOC.Container.Resolve<UpdateOrderPageModel>();
        UpdateOrder.OrderItemUpdated += U_OrderItemUpdated;          
        await CoreMethods.PushPopupPageModel<UpdateOrderPageModel>(SelectedOrderItem,true);
    }

This is not working OnOrderItemUpdated not firing ..

Create Spinner Time picker on Xamari forms Android

$
0
0

My question is simple. Is there any way to create

Something like that instead of this ugly picker on android, and keep default one on IOS

Using visual state manager with a controltemplate

$
0
0

Hi everyone, apologies if this has been answered already. I've got a xamarin forms shell app and I'm trying to use visual state manager on a page that has a ControlTemplate called BasicPageTemplate set in the ContentView. When the GoToState method fires it's crashing with a targetName cannot be null error, which doesn't happen if I remove the ControlTemplate property. This suggests to me that there's an issue with the binding context but I can't work out how to get around it. My (simplified) xaml is below. Have I missed something obvious or is this an issue with forms? Many thanks.

<?xml version="1.0" encoding="UTF-8"?>
<views:BasePage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Views.VisualStateTestPage"
             x:Name="visualStateTestPage"
             xmlns:views="clr-namespace:MyApp.Views;assembly=MyApp"
                Shell.TabBarIsVisible="False" Shell.FlyoutBehavior="Disabled">
    <ContentView x:Name="contentView"
        ControlTemplate="{StaticResource BasicPageTemplate}">                              
            <StackLayout x:Name="stackLayout">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup Name="ValidityStates">
                        <VisualState Name="Valid">
                            <VisualState.Setters>
                                <Setter TargetName="entry"
                                        Property="Entry.BackgroundColor"
                                        Value="Red" />
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState Name="Invalid">
                            <VisualState.Setters>
                                <Setter TargetName="entry"
                                        Property="Entry.BackgroundColor"
                                        Value="Blue" />
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Button x:Name="button" Clicked="button_Clicked"></Button>
                <Entry x:Name="entry" ></Entry>
            </StackLayout>                            
        </ScrollView>
    </ContentView>
</views:BasePage>

HttpClient GetAsync never returns

$
0
0

I have a button thats hooked up with a Command in ViewModel as following:

public string VINNumber {get; set;}
public string API_KEY {get; set;}
Command _DecodeVINCommand;
public Command DecodeVINCommand {
    get { return _DecodeVINCommand ?? (_DecodeVINCommand = new Command( ()=> { ExecuteDecodeVINCommand(); })); }
}
private async Task ExecuteDecodeVINCommand() {
    using (HttpClient client = new HttpClient())
    {
        client.BaseAddress = new Uri("https://api.edmunds.com/api/");
        var response = await client.GetAsync("vehicle/v2/vins/" + VINNumber + "?fmt=json&api_key="+API_KEY);
        if (response.IsSuccessStatusCode)
        {
            var str = await response.Content.ReadAsStringAsync();
            var temp = JsonConvert.DeserializeObject(str);
        }
    }
}

This doesnt work for some reason, as it never returns to response.IsSuccessStatusCode. I use the exact same thing in another Windows Form test project and also postman and in both scenarios, it works fine.

Could someone help?


WebView difficulties

$
0
0

I am new to Xamarin and am trying to port an application that I once wrote for Windows Phone to Android, iOS and eventually Duo.
I have an html page that i need to display. There is embedded JavaScript in the html. In Windows Phone, once the page was loaded, I was able to execute the code with the following:
webBrowser.IsScriptEnabled = true;
webBrowser.InvokeScript("InitPage", dayOfWeek.ToString()....)
where "InitPage" is a function inside the html document.

(I am using the same html file for this app - I would would rather not change it if not necessary)
I have decided to use WebView to display the html.
I have added a callback: webView.Navigated += WebView_Navigated;
and in the callback, I think i need to call EvaluateJavaScriptAsync

I cannot figure out how to call the InitPage method and pass the required params with it.

ALSO, I can't seem to get the view to scroll.

Am I using the wrong control? I would appreciate any help in getting me past this roadblock
thanks

share Authentication access token

$
0
0

Hi
I Have xamarin forms application, authenticate with asp.net membership and give accesstoken after authenticate.
In other platforms (ex silverlight, javascrip libs ....), this token access shared accross all requests to server (ex webclient,httpclient, image source request and ...) and all requests send it to server automaticaly
how can I share this token on xamarin forms for all requests?
I cant set cookies for all requests handly. because some of them like imagesource does not have any way to set it

Collection and ViewStateManager

$
0
0

I have a page with a atcklayout that contains a collectionviewand followed by another stacklayout. I have followed this

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/selection#change-selected-item-color

to change the selection backgroundcolor but it changes the backgroundcolor of the stacklayouot as well. I guess the stacklayouts "state" is "normal" so it uses the normal state color. That is because you define the VSM relative to the root element on the page. Targetting the second stacklayout doesn;t wrk either. any suggestions?

Binding not working

$
0
0

Hi, I have been trying to get a binding to work so that the back button is disabled once it has been clicked on. This is all done in MyContentPage which is inherited by all the pages within the App. There is not command on the button so that shouldn't be interfering with my binding.

Button to be enabled/unenabled:

        Button testButton = new Button()
                {
                    Text = "Test"
                };

                testButton.Clicked += TestButton_Clicked;
        testButton.BindingContext = this;
                testButton.SetBinding(Button.IsEnabledProperty, nameof(BackButtonEnabled));
    private void TestButton_Clicked(object sender, EventArgs e)
        {
            this.BackButtonEnabled = false;
        }

Property and property changed code:

        private bool _backButtonEnabled = true;
        /// <summary>
        /// Allows us to disable the back button when it is clicked so that we don't click on it multiple times.
        /// </summary>
        public bool BackButtonEnabled
        {
            get { return _backButtonEnabled; }
            set
            {
                if (value != _backButtonEnabled)
                {
                    _backButtonEnabled = value;
                    OnPropertyChanged(nameof(BackButtonEnabled));
                }
            }
        }

        protected override void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

I have also done the SetBinding() with a converter. The converter triggers when the bind is set but not when the Property Changed event has been triggered. All the this keywords appear to be picking up the Settings page (that inherits this class). It is pretty much exactly like another binding I have elsewhere in the App so I don't understand what I am doing wrong - can anybody else spot anything?

Thanks

How can one set the Backgroud color of a disabled flyout menu item in a shell in Xamarin.Forms?

$
0
0

I have a Flyout menu Item list in a Shell. Some items are disabled based on certain conditions.
E.g
public AppShell()
{
this.Items[1].Enabled = false;
this.Items[2].Enabled = false;
//Background Color? How
}

I have tried the SetValue method to attempt to change the Background color properties of the flyout menu items but no luck.

Viewing all 89864 articles
Browse latest View live


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