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

Error: To Many Variables SQLite

$
0
0

hi peoples,
my name's Leonardo I have a problem in xamarin forms and I need a help in query using execute of SQLite.

I have a solution and one query "db.Execute("delete from table where OID in (? ? ? ? ? ? ?)", List.ToArray()), but this query get a exception "To many Variable",
I know that the SQLite exists a Max value of parameters and I need increase this value, I need help please... the that do?

Thanks

Sorry, my English is bad.


Data Binding issue

$
0
0

Dear all,
I am stucked with a data binding problem.
In my project, a simple TCP connnection checker, I create a TCPListener that handles connection of other devices.
Now what I want to do is adding the connected devices information into a ListView

The Model contains the AsynchronousSocketListener class which handles correctly the connections.
The ViewModel contains a list of TCPConnectedDevices and generates associated propertychange events.
The View (TCPPage class) creates the AsynchronousSocketListener, and a timer checks every second the list of TCPConnectedDevices updated in the Model.

When creating the Model, I insert some "test" connectedDevices into the list, this works fine, the devices are shown on the view.

Nevertheless, when a new connection occurs, the new list elements generated in the AcceptCallback are not shown.

One strange thing is that the PropertyChanged is raised in the viewmodel, and when setting breakpoints in the code (when the timer calls checkForConnectedDevices), I can see that the tcpViewModel.ConnectedDevices has 6 elements (the 5 "test" items that are shown on the view, and the new device that is not shown on the view)

Do you have an idea of what I do wrong?
Thanks in advance.
By the way, the test is done on an android device

The code follows ....

Code in the Model :

    private List<TCPConnectedItem> connectedItems = new List<TCPConnectedItem>();

    public AsynchronousSocketListener()
        {
            for (int k=0;k<5;k++)
            { 
        // "test" connectedDevices
                TCPConnectedItem tmpItem = new TCPConnectedItem();
                tmpItem.IPAdress = "127.0.0." + k.ToString();
                tmpItem.MACAdress = "MAC 1";// 127.0.0.1";
                tmpItem.color = Color.Green;
                connectedItems.Add(tmpItem);//*/
            }
        }

    public List<TCPConnectedItem> getConnectedDevices()
        {
            return connectedItems;
        }

        public void AcceptCallback(IAsyncResult ar)
        {   
        //Accepts connections and updates the model's list of connected devices 

        // Update the list: 

                TCPConnectedItem newItem = new TCPConnectedItem();
                newItem.IPAdress = listener.LocalEndPoint.ToString();
                newItem.MACAdress = listener.LocalEndPoint.ToString();
                newItem.color = Color.Green;

                connectedItems.Add(newItem);
        }

Code in the View:

    public TCPPage()
        {
                InitializeComponent();

           tcpViewModel = new TCPViewModel();

            // Set binding context:
                BindingContext = tcpViewModel;

                myIP = App.IP;

                tcpViewModel.MyIP = App.IP;             // This works fine

                // Start server socket for listening to entering connections
                myAsyncSocketListener = new AsynchronousSocketListener();

                Thread listenerThread = new Thread(new ThreadStart(myAsyncSocketListener.StartListening));

                listenerThread.Start();

                //Timer
                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
                if (myAsyncSocketListener!=null)
                    { checkForConnectedDevices(); }


                    return true;
        });
        }

        private void checkForConnectedDevices()
        {
                List<TCPConnectedItem> updatedList= myAsyncSocketListener.getConnectedDevices();
                tcpViewModel.ConnectedDevices = updatedList;
        }

Code in the viewmodel:

    public class TCPViewModel : INotifyPropertyChanged
    {

         public TCPViewModel()
         {
                ConnectedDevices = new List<TCPConnectedItem>();
         }

        public event PropertyChangedEventHandler PropertyChanged;


        private List<TCPConnectedItem> connectedDevices;
        public List<TCPConnectedItem> ConnectedDevices
        {
                get { return connectedDevices; }
                    set { connectedDevices = value; RaisePropertyChanged(); }
         }

        protected virtual void RaisePropertyChanged([CallerMemberName] string caller = "")
        {
                if (PropertyChanged!=null)
                {
                // Call the change
                PropertyChanged(this, new PropertyChangedEventArgs(caller));
                }
        }
    }   

Xaml code:

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="TCP.Views.TCPPage">


        <ContentPage.Content>
            <StackLayout Orientation="Vertical">

                <ListView x:Name="lv" ItemsSource="{Binding ConnectedDevices}"><!--IsVisible="{Binding IsWiFiEnabled}">-->
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout Orientation="Horizontal">
                                    <BoxView Color="{Binding color}" HeightRequest="40" WidthRequest="40"></BoxView>
                                    <Label Text="{Binding Name}" ></Label>
                                    <Label Text="{Binding IPAdress}" HorizontalOptions="EndAndExpand"></Label>
                                    <Label Text="{Binding MACAdress}" HorizontalOptions="EndAndExpand"></Label>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>

Binding Data Xamarin.Forms

$
0
0

I want to know why we can't put in a class C # with Xamarin.forms "BindingContext = this" but we can do it in a content page (class and .Xaml) ?

Xamarin.Forms Webview: ERR_CONNECTION_REFUSED trying to load local server with EmbedIO

$
0
0

I am trying run a local server for a Xamarin.Forms WebView. This is to get around CORS, and so the html can be structured like a normal page. This works for UWP and iOS, but Android always comes up with an ERR_CONNECTION_REFUSED. Some further details/things I have tried:

  • The App is running it's own server, so it is not the case of trying to access a server on a separate device.
  • Internet permission is enabled.
  • The path to the files do exist, otherwise the Webserver would fail to start.
  • Link to the local server nuget package: https://github.com/unosquare/embedio

Below is an outline of the code I'm using. In practise, I'm using a custom renderer, injecting Javascript to access platform features, etc. but this should simplify it:

The class that creates and starts the WebServer with EmbedIO:

public class LocalWebServer: IDisposable
{

public static string Url = "http://localhost:8787/";

private readonly string _filePath;
private WebServer _server;

public LocalWebServer(string filePath)
{
    _filePath = filePath;
}

public void StartWebServer()
{
    _server = new WebServer(Url);

    _server.RegisterModule(new LocalSessionModule());
    _server.RegisterModule(new StaticFilesModule(_filePath));
    _server.Module<StaticFilesModule>().UseRamCache = true;
    _server.Module<StaticFilesModule>().DefaultExtension = ".html";
    _server.Module<StaticFilesModule>().DefaultDocument = "index.html";
    _server.Module<StaticFilesModule>().UseGzip = false;



    Task.Factory.StartNew(async ()=>
    {
        Debug.WriteLine("Starting Server");
        await _server.RunAsync();
    });
}

public void Dispose()
{
    _server?.Dispose();
}

}

Code which starts the server and displays the webview:

public App()
{
    InitializeComponent();

    //Create and display a Webview
    _webView = new WebView();
    MainPage = new ContentPage()
    {
        Content = _webView,
    };
}

protected override async void OnStart()
{
    //Service which can initialize app for first time use, and stores
    //the folder location for the html page on each platform
    var htmlService = DependencyService.Get<IHandleHtmlContentService>();

    //Local webserver
    var localWebServer = new LocalWebServer(htmlService.DirectoryPath);

    //This is just a function that loads the html content from the
    //bundle resource or assets into a folder. Will only really
    //matter during the first time the App boots up.
    await htmlService.InitializeHtmlContent();

    //Start the Webserver
    localWebServer.StartWebServer();

    //Navigate to the webserver
    _webView.Source = LocalWebServer.Url;
}

I'v been bashing my head on this for a while, so any help would be appreciated. If you need any more details, let me know.

Integrate FLIC-buttons to Xamarin.Forms

$
0
0

Hi lovely community,

I've got a small question. I bought a flic button from https://flic.io/ and I'd like to integrate it in my Xamarin.Forms project.

It works with Bluetooth and emits data to the smartphone when pressing or holding it. (Up/Down, DoubleClick and longpress events).

But https://flic.io/ doesn't offer any C# library that works with Xamarin.Forms. Only the SDK's for iOS and Android (native) are available and not made with the C# syntax.

So, now I'm staying here and I'm about to cry. I've been trying it with bluetooth scanning, and ended up finding the device with UUID and name but I couldn't create a connection to it, to read the data.

Can anyone explain or offer me any solution to work on this? I'm open to share the ready standalone code with the community for the next guys looking for it, because Flic-buttons (smartbuttons) are really nice!

P.S.: I'm working on an application to save a lot of lifes or injuries. So if anyone gives me the perfect solution, I will credit their name and website into this application, which may come out big very soon.

Thanks a lot! :-)

Correct place to store things securely

$
0
0

I'm doing some work with azure mobile services which requires me to store both an application key, and also cache user authentication information locally (not passwords, just a token).

Is there a standard approach to storing / caching something like this with Xamarin Forms?

Unable to observe page navigation using F# Async support in Xamarin.Forms

$
0
0

I'm unable to observe page navigation.

Command:

member x.AddBankcard =    DelegateCommand( (fun _ -> async { do! navigate() 
                                                           } |> Async.RunSynchronously 
                                                             |> ignore ) ,
                                            fun _ -> true) :> ICommand

Publish navigation request:

let navigate() =

    account 
     |> PageRequest.AddBankcard 
     |> broadcastToAsync pageRequesthandlers     

Notify subscribers of request:

let broadcastToAsync<'a> (handlers:(list<'a -> Async<unit>>)) (msg:'a) : Async<unit> =

    async { handlers |> List.map (fun handle -> async { do! handle msg }) |> ignore }

Handle navigation:

let handle = function
    | PageRequest.AddBankcard _ ->
        page |> function 
        | :? UI.AddBankcard as pageRequest ->
            ...
            async { do! navigationPage.PushAsync(pageRequest) |> Async.AwaitTask }

        | _ -> async { () }
    | _ -> async { () }

Note:

  1. No page navigation occurs.

  2. I don't receive any exceptions.

  3. I don't see any clues in the output window

  4. My hunch is I'm not using async correctly.

    async { do! navigationPage.PushAsync(pageRequest) |> Async.AwaitTask }

UPDATED:

I also tried the following:

let navigationPage = (app:?>Application).MainPage:?>NavigationPage

let navigate () = async  {
    do! navigationPage.PushAsync(pageRequest) |> awaitTask
}

navigate() |> Async.RunSynchronously |> ignore

Here's the source code

Add play pause buttons to notification tray

$
0
0

Hi,
I would like to have a a tile similar to what music apps do where there is a box in the notification tray that is always there when the app is running and has play/pause buttons that i could catch when my app is backgrounded.

Can anyone point me in the right direction to accomplish this?


Has anybody updated WrapLayout from Evolve13 to avoid the deprecated GetSizeRequest?

$
0
0

Has anybody updated WrapLayout from Evolve13 to avoid the deprecated GetSizeRequest method?

See https://github.com/conceptdev/xamarin-forms-samples/blob/master/Evolve13/Evolve13/Controls/WrapLayout.cs

If so, how did you do it? Calling OnMeasure (once worked around the fact it is protected rather than public), which is what the deprecated warning says to use, returns a different result. In the context of WrapLayout, that results in things being clipped.

I can obviously just replicate the existing GetSizeRequest code, but that's presumably not the ideal option if XF is being updated to use OnMeasure instead.

Xamarin.Forms 3.2 includes a TitleView but how do I use this in the iOS Large Tile View when shown

$
0
0

Xamarin Forms 3.2 includes a new NavigationPage.TitleView property which is great and works OK in a normal Navigation Bar. But on iOS and trying to use PreferLargeTitles, it doesn't appear in the large title area, just the top area when the large title is not displayed.

How can I insert this into the Large Title Display area?

BindingContext not working after Xamarin update

$
0
0

It's probably my fault but I can't figure out what the problem is. I have an app with a collapsable listview and I have a button in a row which can be clicked to decollapse the row. This worked great with the same code I have now, but now it gives me an error: Xamarin.Forms.Xaml.XamlParseException Position 77:37. Can not find the object referenced by 'PredictView'

The button is in a groupheader template, the binding to other items works.

In the PredictView.xaml file:
<ContentPage.BindingContext> <local:PredictViewModel /> </ContentPage.BindingContext>

Line 77(error line) of the same file:
<Button Image="{Binding StateIcon}" CommandParameter="{Binding .}" Command="{Binding BindingContext.ExpandCommand, Source={x:Reference Name=PredictView}}" HorizontalOptions="EndAndExpand" VerticalOptions="Center" Margin="0, 0, 12, 0" Style="{StaticResource buttonTransparent}"/>

Previewing XAML File in Xamarin Forms

$
0
0

Considering that none of these work, what does please?

Previewer
LiveReload
XamarinLive Player

How can I debug my XF app on Android without having to grant the app permissions each time?

$
0
0

Every time I start VS debugger for my app which I'm debugging on my Android 8.1 phone I have to grant permissions. How do prevent my app from losing its permissions when I debug it?

ListView memory leaks

$
0
0

I have a Xamarin Forms application. On the main page there is a ListView, every view cell contains text with image. When I start to scroll from beginning to end, after that from the end to the beginning and again and again, the app crashes. Any scrolling increases the allocated memory and after several steps the app crashes.

<ListView 
                ItemsSource="{Binding ViewData}"
                ItemAppearing="OnItemAppearing"
                HasUnevenRows="True"
                SeparatorVisibility="None"
                x:Name="NewsAndFeedListView">
        <ListView.ItemTemplate>
            <DataTemplate>          
                <ViewCell>
                    <ViewCell.View>
                            <Grid>
                                <ffimageloading:CachedImage  Grid.Row="0" DownsampleToViewSize="True" Aspect="AspectFill"       x:Name="MainPhoto">
                                    <ffimageloading:CachedImage.GestureRecognizers>
                                        <TapGestureRecognizer Tapped="MainPhotoTapped" NumberOfTapsRequired="1"/>
                                    </ffimageloading:CachedImage.GestureRecognizers>
                                </ffimageloading:CachedImage>
                                <Label Text="Click here"></Label>
                            </Grid>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

The image's source is set in the code behind in the Viewcell's BindingContextChenged method. Is there some resolution for this problem?

UI control event handlers - Not running on (UI) MainThread - Runtime errors updating UI from events

$
0
0

I'm updating UI controls in my event handlers and intermittently on different devices I get runtime exceptions because the code cannot update the UI from any thread besides the Main (UI) Thread.

I wrapped my updates inside Device.BeginInvokeOnMainThread(...) which fixed the problem but the whole thing seems wrong somehow.
I completely understand that updates to the UI must be serialized on the Main Thread but 80% of event handler code interacts with the UI so why are UI generated event handlers not running on the UI thread? If I want to do something in the background I would prefer to explicitly start an async method call.

Unless I'm misunderstanding something here I need to wrap the majority of my event handler code entirely inside Device.BeginInvokeOnMainThread(....) calls?


How to open specific page in application from URL Shared link

$
0
0

I need to do two things : First , I want to share Model to social media For example I have product which has title , text, id(or specific url)
I use share.plugin to share this model , Second , I want when user click the link if app is installed it navigate to specific page
else it navigate to web site page I followed links which talks about deep linking and app indexing but i didn't find something like i want

Note : I Used prism for xamarin forms

Any help ?

How to disable scrolling on WebView

$
0
0

Hello friends,

I'm trying to disable the scroll on the webview, however I could not find a workaround yet.
I was expecting to use something like this: _webView.ScrollView.ScrollEnabled = false;

do you know how can I do it?

I'm using Xamarin.Forms 1.3.0 stable version

Thanks in advance

webview

$
0
0

how to leave the webview with the same visibility of the browser desktop pc?,without being that compact broser of the cell phones

Need tutorial about Facebook Ads Network?

$
0
0

As the title, I need tutorial about Facebook Ads Network in Xamarin.Forms?
Thank you!

How to read PDF417 in Xamarin Forms?

$
0
0

Hi everybody!
I need read Barcode PDF417, How to read PDF417 in Xamarin Forms?
Thank!

Viewing all 77050 articles
Browse latest View live


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