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

FlowListView "FlowLoadingCommand" is not being called

$
0
0

I have implemented daniel luberda's FlowListView, and am trying to make an infinite loading FlowListView. However, for some reason I cannot get the loading command to get called, and I cannot seem to figure out why.

I have an ICommand implementation:
"public ICommand LoadingCommand
{ get; private set;}"

Which is begin set in the VM's contructor
"LoadingCommand = new Command(async () =>
{
await LoadMoreAsync();
});"

And the method itself looks like this:
"private async Task LoadMoreAsync()
{
SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
conn.CreateTable();

        int startIndex = Products.Count;

        await Task.Delay(1000);

        for (int i = startIndex; i < startIndex + 2; i++)
        {
            try
            {
                Products.Add((ProductModel)(conn.Get(i, new TableMapping(typeof(ProductModel), CreateFlags.None))));
            }
            catch (System.InvalidOperationException)
            {
                System.Diagnostics.Debug.WriteLine("No more elements to load");
            }

        }
        conn.Close();

        flowIsLoadingInfinite = false;
    }"

My XAML page file looks like this:

"

<StackLayout>
    <Button Command="{Binding ClickedCommand}" Text="Click me to add items"/>

    <flv:FlowListView x:Name="flowListView" FlowColumnCount="2" SeparatorVisibility="None" HasUnevenRows="True"
                      BackgroundColor="Azure" FlowRowBackgroundColor="LightGray"
                      FlowTappedBackgroundColor="Red" FlowIsLoadingInfiniteEnabled="True"
                      FlowItemsSource="{Binding Products}"
                      FlowIsLoadingInfinite="{Binding FlowIsLoadingInfinite}"
                      FlowLoadingCommand="{Binding LoadingCommand}"
                      FlowTotalRecords="{Binding TotalRecords}">

        <flv:FlowListView.FlowLoadingTemplate>
            <DataTemplate>
                <ViewCell>
                    <Label
                        HorizontalTextAlignment="Center"
                        VerticalTextAlignment="Center"
                        TextColor="Black"
                        Text="Loading..."
                    ></Label>
                </ViewCell>
            </DataTemplate>
        </flv:FlowListView.FlowLoadingTemplate>

        <flv:FlowListView.FlowColumnTemplate>
            <DataTemplate>
                <Grid Padding="5">
                    <BoxView Color="White" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="0"/>
                    <StackLayout Padding="5" Grid.Row="0">
                        <Image Source="{Binding ProductImgUrl}" HeightRequest="120" Aspect="AspectFill" HorizontalOptions="Center" VerticalOptions="Center"/>
                        <Label Text="{Binding ProductTitle}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Center"/>
                        <Label Text="{Binding ProductDescription}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"  HorizontalTextAlignment="Center"/>
                    </StackLayout>
                </Grid>
            </DataTemplate>
        </flv:FlowListView.FlowColumnTemplate>

    </flv:FlowListView>
</StackLayout>

"


How to put image in Sqlite database ?

$
0
0

Hi guys i created database in my Xamarin project , and I want to put images also in database,small icons ...How can I do that ?

My database look like this

Public class Person
{
public string Photo {get;set;}
}
How to set now a photo here in database ?

how to shared drawables betwen 2 android projects?

$
0
0

Does anybody know how to share drawable folders between 2 android projects? does shared project work for that or there is android class library but not sure if i can shared using it because of namespace?

how to create buttons dynamically in xamarin forms app

$
0
0

hi all,
I wish to create buttons dynamically within a stacklayout in xamarin forms app.. I tried in .cs using stacklayout buttons by statically.. Can anyone tell me how to create buttons dynamically..

Button on Android all caps

$
0
0

I have just noticed that on Xamarin Forms Android, the text label on elements appears in ALL CAPS. Is this by design?

Regards,
Ian

Skiasharp for drawing and photo manipulation?

$
0
0

Hey Everyone,

I've been tasked to add a feature in are Xamarin.froms App for drawing over an image from the users gallery or recent photo then save the edited image back into the gallery.

Half of this feature is completed thanks to the media plugin. My Issue would come to editing the image to draw over it in xamarin. Luckily, I found the SkiaSharp nuget package that can help in creating 2D graphics in a cross-platform application.

I have not made a feature like this before in xamarin. I found that the xamarin documents lacked the information to adding the canvas into the xamarin page and that i can't seem to get the current demo of Skiasharp from github to work on my computer. So My question would be:

  • Is it possible to create the feature of editing an image with Skiasharp? is there an easier method?
    as well as:

  • How can I implement Skiasharp to work in this method?

How to copy a file to install folder in Xamarin Forms?

$
0
0

Hi everybody!
How to copy a file to install folder in Xamarin Forms?
Ex: I have my sqlite.db3 with some data row. I want copy this file to every platform project and working with my database?
Thank you!

how to handle the Navigation Bar in iphone X

$
0
0

Hi, I have an xamarin forms app when I testing in iphone the Navigation Bar overlap the Status Bar in almost all iphone devices except in the iphone X, I found a code for solve the overlap but in iphone X now the Navigation Bar don't look well, someone can help me??, the code I used is:
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);


Working with exist Database file in Xamarin Form?

$
0
0

Hi everybody!
I create a Database SQLite file manually, How to make Xamarin Form working with this exist DB file?
Thank you!

Drag and Drop in UWP and iOS (Xamarin Forms)

$
0
0

Let's say we have a set of positions and we have to drag filled position and drop into empty position.
In UWP render the custom control and

  1. add private field

    private DragDropGestureHandler dragAndDropHandler = new DragDropGestureHandler();
    
  2. in OnElementPropertyChanged function

    protected override void OnElementChanged(ElementChangedEventArgs<PositionCustomView> e)
    {
    
        base.OnElementChanged(e);
    
        if (e.OldElement == null)
        {
            this.CanDrag = true;
            this.AllowDrop = true;
            this.DragOver += dragAndDropHandler.PositionCustomViewRenderer_DragOver;
            this.DragStarting += dragAndDropHandler.PositionCustomViewRenderer_DragStarting;
            this.Drop += dragAndDropHandler.PositionCustomViewRenderer_Drop;
        }
    
        if (e.NewElement == null)
        {
            this.CanDrag = false;
            this.AllowDrop = false;
            this.DragOver -= dragAndDropHandler.PositionCustomViewRenderer_DragOver;
            this.DragStarting -= dragAndDropHandler.PositionCustomViewRenderer_DragStarting;
            this.Drop -= dragAndDropHandler.PositionCustomViewRenderer_Drop;
        }
    }
    
  3. DragDropGestureHandler

    public class DragDropGestureHandler
    
    {        
        public void PositionCustomViewRenderer_DragStarting(UIElement sender, DragStartingEventArgs args)
        {
            var viewRenderer = sender as PositionCustomViewRenderer;
            var element = viewRenderer?.Element;
            if (element.AllowMove)
            {
                args.Cancel = false;
                args.Data.Properties.Add("customView", (element));
                element.PositionMovingCommand?.Execute(element.Position);
            }
            else
            {
                args.Cancel = true;
            }
        }
    
    public async void PositionCustomViewRenderer_Drop(object sender, DragEventArgs e)
    {
        var viewRenderer = sender as PositionCustomViewRenderer;
        var element = viewRenderer?.Element;
        var result = e.DataView?.Properties?.
                    SingleOrDefault(p => p.Key == "customView" && p.Value.GetType() == typeof(PositionCustomView));
        var positionCustomView = result?.Value as PositionCustomView;
    
        element.PositionMovedCommand?.Execute(new Tuple<int, int?, int>(PositionCustomView.Position, PositionCustomView.SessionId, element.Position));
    }        
    
    public void PositionCustomViewRenderer_DragOver(object sender, DragEventArgs e)
    {
        var viewRenderer = sender as PositionCustomViewRenderer;
        var element = viewRenderer?.Element;
        if (element.AllowDrop)
        {
            e.AcceptedOperation = DataPackageOperation.Copy | DataPackageOperation.Move;
        }
        else
        {
            e.AcceptedOperation = DataPackageOperation.None;
        }
    }
    
    }
    

In iOS render the custom control and

1.add private fields

private UIDragInteraction dragInteraction = null;
    private UIDropInteraction dropInteraction = null;
    private DragDropGestureHandler dragDropGestureHandler = new DragDropGestureHandler();
  1. in OnElementPropertyChanged function

    protected override void OnElementChanged(ElementChangedEventArgs<View> e)
    {
        base.OnElementChanged(e);
        dragInteraction = new UIDragInteraction(dragDropGestureHandler);
        dropInteraction = new UIDropInteraction(dragDropGestureHandler);
    
    
        if (e.OldElement == null)
        {
            this.UserInteractionEnabled = true;
            this.AddInteraction(dragInteraction);
            this.AddInteraction(dropInteraction);
        }
        if(e.NewElement == null)
        {
            this.RemoveInteraction(dragInteraction);
            this.RemoveInteraction(dropInteraction);
        }
    
    }
    
  2. DragDropGestureHandler

    public class DragDropGestureHandler : NSObject, IUIDragInteractionDelegate, IUIDropInteractionDelegate
    {
    
    public UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session)
    {
        var viewRenderer = interaction.View as PositionCustomViewRenderer;
        var view = viewRenderer.Element as PositionCustomView;
        if (view.AllowMove)
        {
            view.PositionMovingCommand?.Execute(view.Position);
            var provider = new NSItemProvider(new NSString($"{view?.Position}:{view?.SessionId}"));
            var item = new UIDragItem(provider);
            return new UIDragItem[] { item };
        }
        else
        {
            return null;
        }
    }
    [Export("dropInteraction:sessionDidUpdate:")]
    public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session)
    {
        var viewRenderer = interaction.View as PositionCustomViewRenderer;
        var view = viewRenderer.Element as PositionCustomView;
        UIDropProposal proposal = new UIDropProposal(UIDropOperation.Copy);
        if (view.AllowDrop)
        {
            proposal = new UIDropProposal(UIDropOperation.Copy);
        }
        else
        {
            proposal = new UIDropProposal(UIDropOperation.Forbidden);
        }
        return proposal;
    }
    
    
    [Export("dropInteraction:performDrop:")]
    public void PerformDrop(UIDropInteraction interaction, IUIDropSession session)
    {
        var viewRenderer = interaction.View as PositionCustomViewRenderer;
        var view = viewRenderer.Element as PositionCustomView;
        session.LoadObjects<NSString>(strings =>
        {
            string string0 = strings[0];
    
            string[] positionSessionIds = string0.Split(':');
            var position = int.Parse(positionSessionIds[0]);
            int? sessionId = (positionSessionIds[1] == null) ? default(int?) : int.Parse(positionSessionIds[1]);
    
            view.PositionMovedCommand?.Execute(new Tuple<int, int?, int>(position, sessionId, view.Position));
        });
    }
    
    }
    

Create Simple Calendar

$
0
0

Hi, I would like to ask you if possible a little help ... I am creating a simple app in mvvm and xamarin.forms, and I am a beginner .. I have a page that, when opened, creates a calendar through code (made of for loops and grids), and inside every cell related to the day writes a daily total in $ proceeds from the DB sqlite .. now, I would like to resolve two issues:

1 - When I change the month, using a button, the page is recharged and regenerates the calendar .. but the loading is heavy, and it takes a second to reload page.

2 - I would like to be able to implement a 'swipe' page, like a carousel, to change the month .. instead of having to hit a button ..

I know there are already calendar controls, but I need a personalized one for my logic needs. Could someone give me suggestions on how to proceed?

Why is the setter of a binding property called for a Stepper?

$
0
0

I'm building an app in Xamarin.Forms in which I want to use a Stepper. I'm using MVVM so I bind the value of the stepper to a value in my model. The stepper is in a (self build) collapsable listview. When a cell is decollapsed it will show the stepper. At the moment the stepper is shown on screen, the "Set" function of the binded property is called. I don't understand why. Shouldn't it call the "Get" function if it wanted to know the current value? Fun fact is that when the corresponding property is "0", the "Set" function is not called when the Stepper is shown on screen. When loading a label the "Get" function is nicely called.

Why is this and how can I solve the problem that I want to call a function to update a database via an api when the stepper is clicked/value is changed? I want to do it the MVVM way, of course I can do it in the code behind but I don't prefer that.

I currently use a different property for the stepper then the actual property with the value, as the value is set in different ways(also when loading from the API) and I don't want the loop that I load something and it updates the value immediately. I tried with the same property as well, but the same problem persists.

XAML
<Stepper x:Name="PredictionStepper" Minimum="0" Increment="1" Value="{Binding PredictionStepper}" IsVisible="{Binding PredictionCanBeAltered}" />

Model
public int PredictionStepper
{
get
{
return Prediction;
}
set
{
Prediction = value;
UpdateManager.Instance().Add(this);
}
}

    public int Prediction 
    { 
        get
        {
            return Prediction;
        }
        set
        {
            Prediction = value;
            OnPropertyChanged("Prediction");
        }
    }

Deploying to IOS devices for beta testing.

$
0
0

I am trying to generate a package that I can deploy to registered devices. I have created a certificate, provision profile, and can successfully deploy to my phone or simulator in Debug mode. I am trying to run as AdHoc, which i think creates a package that I can distribute, but when I do it says it cannot find a provisioning profile.

I have been following the article at:
https://docs.microsoft.com/en-us/xamarin/ios/get-started/installation/device-provisioning/manual-provisioning?tabs=vsmac

I am not ready to submit my app for review, so this Ad-Hoc distribution seems to be the correct approach from what I have read. The article takes me part of the way, but doesn't describe how to create the package or how upload it to Itunes. The article doesn't match my version of Visual studio (17) as well. Any advice on how to accomplish this?

Can i bind an attribute that be inside of other class?

$
0
0

Hi everyone, this is my first post, i'm excited!

I have an issue, i have the nex model:

public partial class UserData
{
[JsonProperty("personalInfo")]
public PersonalInfo PersonalInfo { get; set; }

    [JsonProperty("salaryInfo")]
    public SalaryInfo SalaryInfo { get; set; }

    [JsonProperty("contactInfo")]
    public ContactInfo ContactInfo { get; set; }
}

that is the model where my bindingcontext is suppose to get the data, but i need to make reference to the real attribute inside of each one of that classes, for example:

public partial class SalaryInfo
{
[JsonProperty("hourlyRate")]
public long HourlyRate { get; set; }

    [JsonProperty("payrate")]
    public decimal PayRate { get; set; }
}

i need to binding in my xaml form to PayRate property, how can i do that?

I try with {Binding SalaryInfo.PayRate} but doesn't work.

Any solutions?

Thanks a lot!!

OnSizeAllocated, UseSafeArea, changing layouts by orientation on iPhone X

$
0
0

We use OnSizeAllocated to drastically change our layouts between landscape and portrait modes. Having to do an update, which means I finally have to deal with the iPhone X issue. I've found a problem that I'm not sure how to work around.

Setting the page to UseSafeArea is all fine and good until OnSizeAllocated fires. Seems the width and height for OnSizeAllocated don't take into account the padding placed by UseSafeArea. Likely by design, but it means we don't have a simple way to determine the actual usable width within OnSizeAllocated. I've looked and don't see an easy way to just say if this is an iPhone X reduce the width and height by the padding amount (don't want to do it for all iOS11 phones)

Any ideas on how to deal with this? I've searched for a couple hours and been unsuccessful.

Thanks!


Using SkiaSharp, what is the best way to convert SKCanvas-drawn content into a bitmap?

$
0
0

An app I'm working on needs to dynamically generate bitmap images using vector drawing commands. There are two desired targets: a alpha-channel-friendly bitmap file like .PNG and an ImageSource for binding to Xamarin Forms Image controls, creating and updating app-level DynamicResources, etc.

What is the best way to go about this? Do SKBitmap or SKImage objects have a way to convert to a Bitmap or ImageSource object? Does the SKData object need to produce the raw bytes, and then those are used to hydrate a bitmap object?

ERROR WITH LATEST NUGET v2.5.0.77 "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded

$
0
0

I just got latest stable 2.5.0.77107 and I can't compile anymore

[myUser]\packages\xamarin.forms\2.5.0.77107\build\netstandard1.0\Xamarin.Forms.targets(55,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly [myUser]\.nuget\packages\xamarin.forms\2.5.0.77107\build\netstandard1.0\Xamarin.Forms.Build.Tasks.dll.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

I replaced my user path with [myUser]

it looks like this bug exists since October in the pre-release:

https://bugzilla.xamarin.com/show_bug.cgi?id=60293

Open PDF in Android default PDF reader

$
0
0

Hi,

I'm searching a way to open a PDF (stored in local) in the Android default PDF reader in Xamarin.Forms.
I'm using a webview for iOS but WebViews on Android cannot open a local PDF.

var browser = new WebView ();

if (Device.OS == TargetPlatform.iOS) {
    browser.Source = @App.DocumentUrl;
} else if (Device.OS == TargetPlatform.Android) {
    Device.OpenUri (new Uri (@App.DocumentUrl)); // Don't work
}

Content = browser;

Did someone have a solution ?

Thanks.

Can deploy to iPhone but not iPad 0xe8000087 (kAMDIncorrectArchitectureError)

$
0
0

I have a Xamarin Forms app that works well on Android and iPhone, but just tried deploying to an iPad Mini. It's running iOS 9.3.5 (which is it's max) but I'm targetting 8, so I beleive it should work (as it does to 3 different iPhones).

It goes through all the motions, counting up the % of deployment then errors out with:

Launch failed. The app 'test.iOS' could not be launched on 'Test iPad'. Error: error MT1006: Could not install the application '/Users/Me/Library/Caches/Xamarin/mtbs/builds/test.iOS/93855ffa612fde083ef55b36d6f598cd/bin/iPhone/Debug/test.iOS.app' on the device 'Test iPad': AMDeviceSecureInstallApplicationBundle returned: 0xe8000087 (kAMDIncorrectArchitectureError).. Please check the logs for more details.

I've looked at the config pages I can find, but can't see why this would be building for AMD and not ARM, nor why it would do this for an iPad but not iPhone.

Just for completenss, I build a test app in XCode and it deploys and runs perfectly.

Any ideas?

How to avoid swipe gestures conflict between MasterDetail page and UITableview Row action

$
0
0

We have MasterDetail page and in the detail page I have a Listview implemented. Due to the lag in listview, we decided to implement in Native iOS renderer for Listview. That is mostly completed except for the UITableviewCell Row actions. The Row action swipe is not working properly. Then I found the issue is with Swipe gesture of Master Detail page.

In native iOS, it can solved using the shouldRecognizeSimultaneouslyWithGestureRecognizer. I can find the corresponding property in UIGestureRecognizerDelegate, but don't know how to implement this.

Only I have fully implemented native control for UITableviewCell. The UITableView is still rendered using Xamarin.Forms renderer only. I tried to implement the ShouldRecognizeSimultaneously in ListViewRenderer but not working.

Hope I will get some sample, how to implement this.

Viewing all 79144 articles
Browse latest View live


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