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

how set Loading image - Error image to Image

$
0
0

I don't want to use this plugin ffimageloading

Introduce new tools


how we bind the hidden filed value with DatePicker?

$
0
0

basically I use DatePicker in ListView and I want to add new id or name bind with DatePicker for when I change select date and want this given id or name in selected date method? Help me as soon as possible please.

Sorry for poor English

Behavior crashes "Operation is not valid due to the current state of the object"

$
0
0

I have added a Behavior to a CheckBox to issue a Command, then discovered that the Command could not be found because the BindingContext was a collection item, not the ViewModel. I used a RelativeSource on my Binding to reference the ViewModel but now get the Exception thrown identified in the title. Note that I use the same idiom in the ReturnCommand for an Entry below the CheckBox and it works flawlessly. Scratching my head on this one... Any suggestions?

XAML:

...

<ContentPage.BindingContext>
    <vm:ShoppingListViewModel/>
</ContentPage.BindingContext>

<ContentPage.Content>
    <CollectionView ItemsSource="{Binding MyShoppingList}" 
                    SelectionMode="None"
                    EmptyView="There are no items in your Shopping List">
        <CollectionView.ItemsLayout>
            <LinearItemsLayout Orientation="Vertical" 
                               ItemSpacing="2"
                               SnapPointsType="None"/>
        </CollectionView.ItemsLayout>
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <Grid Padding="5,0,5,0" ColumnDefinitions="28, 7*, 3*">

                    <CheckBox x:Name="completedCheckBox" Grid.Column="0" 
                                IsChecked="{Binding Completed, Mode=TwoWay}" 
                                HorizontalOptions="Center" 
                                VerticalOptions="Center"
                                Style="{StaticResource checkBoxStyle}">
                        <CheckBox.Behaviors>
                            <behaviors:CheckBoxCommandBehavior 
                                    Command="{Binding ToggledCommand, 
                              Source={RelativeSource AncestorType={x:Type vm:ShoppingListViewModel}}}"           <--- Offender!
                                    CommandParameter="{Binding .}">
                            </behaviors:CheckBoxCommandBehavior>
                        </CheckBox.Behaviors>

                    </CheckBox>

                    <Entry Text="{Binding ItemName}"  Grid.Column="1" HorizontalOptions="Start" VerticalOptions="Fill" WidthRequest="325"
                            ReturnCommand="{Binding ShoppingListItemChanged,
                                                             Source={RelativeSource AncestorType={x:Type vm:ShoppingListViewModel}}}"
                            ReturnCommandParameter="{Binding .}"
                            Completed="TextEntry_Completed"
                            IsSpellCheckEnabled="False"
                            IsReadOnly="True"
                            x:Name="shoppingListItemEntry">
                        <Entry.Effects>
                            <effects:LongPressEffect />
                        </Entry.Effects>
                        <Entry.Triggers>
                            <DataTrigger TargetType="Entry"
                                         Binding="{Binding IsChecked, Source={x:Reference completedCheckBox}}"
                                         Value="True">
                                <Setter Property="TextColor"
                                        Value="{AppThemeBinding Light={StaticResource Light_InactiveColor},
                                                                Dark={StaticResource Dark_InactiveColor}}" />
                            </DataTrigger>
                        </Entry.Triggers>
                    </Entry>

...

How to implement Intent Filter to intercept links with non-web prefix?

$
0
0

Hi,

I'm implementing an Android app which renders notes from HTML into TextViews, with the ability to link either to the web (using http or https prefix) or to other notes in the same application. Meaning, if the user taps a web URL the browser should handle it, but if a link such as my-prefix:// is tapped, it should just be handled within the app.

I'm trying to implement this using intent filters, as suggested by David Hedlund's answer in a Stack Overflow thread (which I'm not yet allowed to include). However I'm struggling to translate this solution to Xamarin. The suggested solution is to add the following intent filter to the Android Manifest:

<intent-filter>
    <category android:name="android.intent.category.DEFAULT" />
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="com.package.name" />  
</intent-filter>

I've implemented this as the following IntentFilter constructor above my MainActivity (adapted for my namespace and choice in prefix):

    [Activity(Label = "MindNote", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter(new[] { Intent.ActionView },
        Categories = new[] { Intent.CategoryDefault },
        DataScheme = "MindNote")]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
        }

However, this will not even compile, resulting in the following error message:

Member 'Intent.ActionView' cannot be accessed with an instance reference; qualify it with a type name instead

What am I missing here, and should I consider another approach for achieving the result I want?

Xamarin.Forms (iOS & Droid) guide for Azure Notification Hub that actually works as of July 2019?

$
0
0

Ok, I'm getting really tired of this now!
I have an app that haven't been updated for about 3 years. Therefore I'm rewriting the entire app now and all is fine.

Now I'm at the point where I need the new app to use the Azure Notification Hub, with template registrations, as the old one does.

... and it seems everything in relation to Xamarin and Notification Hub have just been forgotten or abandon, because none of the guides I find works.

Even the official one here, doesn't work and complains about some of the classes used in the sample code being obsolete.
https://docs.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-push-notifications-android-gcm

Notifications in mobile apps is such a common thing, I assume, why is it still SO hard to get working? (I know MS is not here to blame for how Google and Apple do the actual notification services, but, Microsoft build Notification Hub as a wrapper and around that - and that idea is brilliant!

This question is already too long..so i stop here :)

So anybody have a Xamarin.Forms (or just a Android and iOS) specific guide to make hook the app(s) up to Notification Hub?

how to add a list data into a picker

$
0
0

I have an API and i want to load API key into picker list how I do that

Switch TapGestureRecognizer not working in listview

$
0
0

Below is my code snippet.

<ListView ItemsSource="{Binding UserList}">
<ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout>
                                        <Switch OnColor="#D27474" ThumbColor="#D27474">
                                            <Switch.GestureRecognizers>
                                                <TapGestureRecognizer Command="{Binding TestCommand}"></TapGestureRecognizer>
                                            </Switch.GestureRecognizers>
                                        </Switch>
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
</ListView>

How can I enable javascript with WebView on UWP

$
0
0

When displaying a webpage using WebView that contains javascript, the javascript is executed fine with iOS and Android.
However on UWP, the script is not execute. How can I enable it to be executed.


on shell how can set bottom navigation between tabbar icon and text spacing?

$
0
0

android and ios. shell renderer how can set bottom navigation between tabbar icon and text spacing?

web api image + json in one go. WHATS THE PROPER WAY?

$
0
0

so this is my code for posting

public async Task AddProduct(int productid, string productCategory, string productColor, decimal unitPrice, string userId,byte[]image)
{

        var client = new HttpClient();

        var model = new Products
        {
            ProductId = productid,
            ProductCategory = productCategory,
            ProductColor = productColor,
           UnitPrice = unitPrice,
            UserId = userId,
            // Image = image <<<< DO I ADD THIS?






        };

        var json = JsonConvert.SerializeObject(model);

      var content = new StringContent(json);
        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

        var response = await client.PostAsync("http://192.168.1.6:44331/api/Products", content);

        return response.IsSuccessStatusCode;

    }

My question is this. and I'm really so confused about this part. in my view there will be add product. thats looks something like this

StackLayout>

    <Entry Text="{Binding ProductColor}" Placeholder="Enter Product Color"/>
    <Entry Text="{Binding ProductCategory}" Placeholder="Enter Product Category"/>
    <Entry Text="{Binding UnitPrice}" Placeholder="Enter Product Cost" Keyboard="Numeric"/>
    <Button Command="{Bingind AddProductCommand}" Text="Add Product"/>





</StackLayout>

in my view model i am just calling that service to a command to add the product. So my question is how can i slid the image there and post it in one go.
Or at least upload the image to azure blob storage and return it as uri then post it with a single command. Give me an idea on how to do that please. I've been reading so much topic about this. and all they teach is how to upload the image without the data along with it

How to use SerialPort sample code in ContentPage Xamarin Forms?

$
0
0

For a project, I need to connect a device having Serial Port to an android smartphone.

I found a sample project here :

https://bitbucket.org/lusovu/xamarinusbserial/get/1d8427ea1da0.zip

The project uses an Activity so it has very basic UI but it works perfectly.

However, I need some more UI so I created a new Xamarin Forms project. I have also designed the contentpage.

But I am unable to use the code from the sample project in my app.

I keep getting compiler errors at certain lines.

Can you help me convert the activity to a Content Page?

FlexLayout v CollectionView??

$
0
0

FlexLayout is just a space and it will try to fit as many items on a row as possible. CollectionView you have to specify the number of columns (or rows) and it does the rest. FL "just works" with different sizes and orientations and CV doesn't. Let this be a lesson. I just spent the morning trying to replace a FL with a CV only to find it didn't really do the job. You specify 2 columns in portrait and it looks bad in landscape.

Anyone else got round this?

Show Touches (iOS)

$
0
0

Hello,

I am trying to find a way to automatically show touches and gestures (iOS only) like this code is trying to accomplish:

http://forums.xamarin.com/discussion/50254/ios-show-touches-free-library

Seems easy enough to get working, but I have a feeling it wasn't designed for Xamarin Forms projects? Using the above code I can either get the touches to show OR get my app controls to respond to the touches (but never both at the same time).

Has anyone done anything similar? Is there a way to capture all touches (to be handled on one layer - the animation) and then pass the touches along so the app behaves as normal? I am trying to find a way to do it once and have it work with the entire application. I want to try and avoid doing special touch handling and animation on each page separately.

I have also tried using a custom UIWindow (along side the default one) and calling MakeKeyAndVisible(). I had SendEvent overridden and calling window.SendEvent(evt) where 'window' is the default UIWindow that Xamarin Forms creates. However, the touches are not received by the app controls.

I have a feeling I'm misunderstanding something so any help would be appreciated.

Thanks,
Kevin

Presence of Binding and BindingContext causing problems when binding to another control 's property?

$
0
0

Hello,

It was hard to formulate the question but here is my problem.
-Entry "entryTransactionAmount"'s Text bound to the TransactionAmount property of my viewmodel. Its IsEnabled property is bound to the Text path of the CustomerName label through a BindingContext.
-I have a button whose Command is bound through the viewmodel also. Its IsEnabled property is bound to the Text path of entryTransactionAmount above through a BindingContext.

The problems I am having are:
1- When the IsEnabled property of the button is set, click on it does not fire. When I remove the BindingContext and the IsEnabled binding, it does fire, but the TransactionAmount property of the viewmodel to which the TransactionAmount entry is bound is null when I break in the viewmodel.
2-When I remove the IsEnabled binding and the BindingContext from entryTransactionAmount, the TransactionAmount value is passed to the viewmodel..

In a nutshell, I am trying to implement the following behavior: user enters an ID and search for a customer. When the customer is found, the customer "card" turns green and the Transaction Amount entry is enabled. User then enters a transaction amount in the entry and that enables the Post button.

It got really tangled up and I am getting lost. Below is my XAML...maybe someone can help these tired eyes. I can share the viewmodel on request. Thank you.

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

<ContentPage.Resources>
    <local:StringCaseConverter x:Key="StringCaseConverterKey"></local:StringCaseConverter>
    <local:StringToBoolConverter x:Key="StringToBoolConverterKey"></local:StringToBoolConverter>
    <local:PositiveValueConverter x:Key="PositiveValueConverterKey"></local:PositiveValueConverter>
    <local:ReadyToPostConverter x:Key="ReadyToPostConverterKey"></local:ReadyToPostConverter>
    <local:StringToColorConverter x:Key="StringToColorConverterKey"></local:StringToColorConverter>
</ContentPage.Resources>

<ContentPage.ToolbarItems>
    <ToolbarItem IconImageSource="logout_white_icon.png" Text="Logout" Clicked="OnLogoutButtonClicked" />
</ContentPage.ToolbarItems>

<NavigationPage.TitleView>
    <StackLayout Orientation="Horizontal">
        <Image Source="sf_icon_180x180" VerticalOptions="Start" HorizontalOptions="Start" HeightRequest="60" WidthRequest="60" />
        <!--<Label Text="Sports Top-Up" HorizontalOptions="StartAndExpand" TextColor="White" VerticalOptions="Center" FontSize="Large" FontAttributes="Bold" />-->
        <StackLayout Orientation="Vertical" >
            <Label VerticalOptions="Start" HorizontalOptions="Start" Font="Bold,Medium">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="{Binding Cashier.first_name, StringFormat='{0} ', Converter={StaticResource StringCaseConverterKey}, ConverterParameter=u}" TextColor="White"/>
                        <Span Text="{Binding Cashier.last_name, StringFormat=' {0}', Converter={StaticResource StringCaseConverterKey}, ConverterParameter=u}" TextColor="White"/>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
            <Label HorizontalOptions="Start" Text="{Binding StaffOnlineBalance, StringFormat='Balance: ${0:C}'}" TextColor="White" Font="Bold,Medium"/>
        </StackLayout>
    </StackLayout>
</NavigationPage.TitleView>

<ContentPage.Content >
    <StackLayout x:Name="outerStack">
        <ScrollView>
            <StackLayout Orientation="Vertical">
                <StackLayout x:Name="SearchUsing" Orientation="Horizontal" Margin="20" >
                    <Label Text="Search Using:" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Start" />
                    <RadioButton x:Name="UserName" Text="User Name"  IsChecked="true" VerticalOptions="Center" CheckedChanged="OnRadioButtonCheckedChanged"/>
                    <RadioButton x:Name="IDCard" Text="ID Card" VerticalOptions="Center" CheckedChanged="OnRadioButtonCheckedChanged"/>
                </StackLayout>
                <StackLayout x:Name="SearchValue" Orientation="Horizontal" Margin="20" >
                    <Label Text="Search Value:" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Start"/>
                    <Entry x:Name="Password" Text="{Binding SearchValue, Mode=TwoWay}" Placeholder="Enter value to search" ClearButtonVisibility="WhileEditing" 
                            HeightRequest="40" HorizontalOptions="CenterAndExpand" Keyboard="Numeric"/>
                    <Button x:Name="SearchButton" Command="{Binding SearchCommand}" Text="Search" TextColor="White" HorizontalOptions="EndAndExpand" 
                            IsEnabled= "{Binding SearchValue, Converter={StaticResource StringToBoolConverterKey}, ConverterParameter=l}"/>
                </StackLayout>
                <Frame BackgroundColor="{Binding CustomerName, Converter={StaticResource StringToColorConverterKey}}" HasShadow="True" Margin="20" CornerRadius="1">
                    <StackLayout Orientation="Vertical">
                        <StackLayout x:Name="Customer" Orientation="Horizontal" Margin="5" >
                            <Label Text="Customer Name:" Font="Bold,Large" VerticalOptions="Center" HorizontalOptions="Start"/>
                            <Label x:Name="CustomerName" Text="{Binding CustomerName}" Font="Bold,Large"  VerticalOptions="Center" HorizontalOptions="Start"/>
                        </StackLayout>
                        <StackLayout x:Name="Balance" Orientation="Horizontal" Margin="5" >
                            <Label Text="Customer Balance:" Font="Bold,Large" VerticalOptions="Center" HorizontalOptions="Start"/>
                            <Label Text="{Binding AccountBalance, StringFormat='${0:C}'}" Font="Bold,Large" VerticalOptions="Center" HorizontalOptions="Start"/>
                        </StackLayout>
                    </StackLayout>
                </Frame>
                <StackLayout x:Name="Amount" Orientation="Horizontal" Margin="20" >
                    <Label Text="Amount:" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Start"/>
                    <Entry x:Name="entryTransactionAmount" Text="{Binding TransactionAmount, Mode=TwoWay, StringFormat='{0:C}'}" Placeholder="Enter credit amount" ClearButtonVisibility="WhileEditing"
                           BindingContext="{x:Reference CustomerName}"
                           IsEnabled="{Binding Path=Text, Converter={StaticResource StringToBoolConverterKey}, ConverterParameter=l}"
                           Keyboard="Numeric" HeightRequest="38"/>
                </StackLayout>
                <Button Margin="10"
                        Command="{Binding PostCreditCommand}"
                        Text="Post" 
                        TextColor="White" 
                        BackgroundColor="#BF043055" 
                        BorderColor="White" 
                        FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"/>
                <ActivityIndicator x:Name="loginActivityIndicator" 
                                                IsRunning="{Binding Loading}"
                                                IsVisible="{Binding Loading}"
                                                IsEnabled="{Binding Loading}"
                                                VerticalOptions="Center" HorizontalOptions="Center" Color="Blue"/>
            </StackLayout>
        </ScrollView>
    </StackLayout>
</ContentPage.Content>

What is EGL_emulation?

$
0
0

While trying to find differences between a working project and non-working one, in the Output of non-working I find entries tagged 'EGL_emulation'. These entries are not found in the output of working project.

What is this and what difference does it make?


How to handle event on an invisible SearchBar ?

$
0
0

Hello,

I'm trying to get a result from a barcode Scanned with a bluetooth device.

As bluetooth scanner work as keyboard, I've made a SearchBar and handle SearchCommand event on it like this :

<SearchBar SearchCommand="{Binding SearchCompleteCommand}" SearchCommandParameter="{Binding Text, Source={x:Reference search_Scanner}}" x:Name="search_Scanner"></SearchBar>

After scanning barcode with my device the result appear in this SearchBar.

But I don't want to show up this SearchBar to users, so I've tried to make it invisible with attribute IsVisible="False"

And now it's invisible the event is not handle, so I'm asking my self, is there another way to do this ?

Thanks for your help,

How is it Master part doesn't need Navigation capabilities, but Detail part does need them?

$
0
0

This is the template code (didn't touch it) of Xamarin.Forms for the main page in MasterDetailPage.

I wonder...How is it that MasterDetailPage.Master doesn't need the capabilities of NavigationPage
(as you can see in the code), but MasterDetailPage.Detail does need it (as you can see in the code).

After all, both of them supply us navigation... :|

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:d="http://xamarin.com/schemas/2014/forms/design"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            mc:Ignorable="d"
            xmlns:views="clr-namespace:TryMasterDetail5_Proj.Views"
            x:Class="TryMasterDetail5_Proj.Views.MainPage">

    <MasterDetailPage.Master>
        <views:MenuPage />
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <NavigationPage>
            <NavigationPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS" Value="tab_feed.png"/>
                </OnPlatform>
            </NavigationPage.Icon>
            <x:Arguments>
                <views:ItemsPage />
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>

</MasterDetailPage>

how to set flyout selecteditem color to gradient in xamarin forms shell

$
0
0

Hi,

is there anyway to set the selected flyout item color to gradient color in xamarin forms shell?

DisplayAlert with confirmation does not display when called from viewmodel

$
0
0

Hi all.

In my view model I define a function
public Func<string, string, bool> DisplayPrompt;
where the first parameter is the title and the second the message passed to the DisplayAlert(title, message, "Yes", "No") call from the view. The third parameter is the return type of the function.

In the view model I make the call
bool answer = DisplayPrompt("Confirm transaction", "Are you sure you want to Deposit Amount $" + AdjustAmount + " on Customer " + CustomerName);
and execution gets stuck here.

In the view, the method is defined as
_vm.DisplayPrompt = new Func<string, string, bool>(DisplayAlertWithPrompt);
...
public bool DisplayAlertWithPrompt(string title, string message)
{
var r = DisplayAlert(title, message, "Yes", "No");
return r.Result;
}

I have tried wrapping both the call in the view model and the code in DisplayAlertwithPrompt in the view inside a
MainThread.BeginInvokeOnMainThread(() =>
{
// Code to run on the main thread
});

but it still gets stuck.

PS: I do have a public Action<string, string> DisplayCustomAlert;
that works fine called from the view model; it calls the DisplayAler(title, message) from the view, without a prompt that is, and it works just fine.

What am I missing?

Thank you!

Prism DI with event attached in constructor

$
0
0

Hi,

I am using the following repo in my Prism XF app to select multiple images from the gallery.

https://github.com/CrossGeeks/MultipleMediaPickerSample

If you check the issues you'll notice there is an issue with the code:

https://github.com/CrossGeeks/MultipleMediaPickerSample/issues/1

I don't really want to go down the route of using Messaging as most answers suggest but if you read this comment...

https://github.com/CrossGeeks/MultipleMediaPickerSample/issues/1#issuecomment-563190605

...osamaelhosany suggests using the IOC container. I'm trying this method as follows:

public class AndroidInitializer : IPlatformInitializer
    {
        public void RegisterTypes(IContainerRegistry containerRegistry)
        {   
            containerRegistry.RegisterSingleton<IMultiMediaPickerService, MultiMediaPickerService>();
        }
}

Then resolving in MainActivity OnActivityResult as so (I've removed SharedInstance in MultiMediaPickerService):

var multimediaPickerService = (MultiMediaPickerService)((PrismApplication)Xamarin.Forms.Application.Current).Container.Resolve<IMultiMediaPickerService>();

multimediaPickerService.OnActivityResult(requestCode, resultCode, data);

In the ViewModel the interface is injected as normal and I am attaching the event to OnMediaPickedCompleted in the ViewModel constructor.

_multiMediaPickerService.OnMediaPickedCompleted -= CreateImageBanks;
_multiMediaPickerService.OnMediaPickedCompleted += CreateImageBanks;

I am noticing that each time I navigate to the page the event is being attached again via the ViewModel constructor. That is to say the first time I enter the page and select Images from the Gallery, CreateImageBanks is fired once. The second time I enter the page and select Images from the Gallery, CreateImageBanks fires twice. The third time...and so on.

Can anyone offer any explanation as to why?

Thanks in advance

Viewing all 79144 articles
Browse latest View live


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