Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

Not calling override method on EvaluateJavascript when window.method is placed inside Angular code

$
0
0

I am trying to inject Javascript to the webivew which was designed using Angular2. Now on button click they wrote a function as shown below

this.nativeAppService.sendToNative({eventName: 'SomeMethod'});
sendToNative(event: NativeEvent) {
if (this._cookieService.get('NativeAppKey') === 'true') {
const window = this.windowRef.nativeWindow;
if (window.messageToNative) {
window.messageToNative(event);
} else if (window.external && window.external.NativeDispatch) {
window.external.NativeDispatch(event.eventName, JSON.stringify(event.parameters));
} else {
console.warn(Not posting event to native app - neither window.messageToNative or window.external.NativeDispatch is not defined.);
}
}
}

now I am writing evaluate javascript as shown below

            Control.EvaluateJavascript("function messageToNative(toast){Android.showToast(toast);}", null);

Here "messageToNative" is the function in aboive script so once I click the button my "showToast" should call but it is not happening

If I am loading samplehtml file with a button and on button click it is calling showToast method but If I am trying to implement the above script its not working fine

Please help me on this.


How to create beam scanner app in xamarin forms for PM80 device

$
0
0

I am new in xamarin forms kindly help me about Point mobile scanner app. This device (delfi PM 80) have built in scanner. If any one have any example kindly help me.
Thanks in advance

The Master detail icon doesn't respond to the FlowDirection.RightToLeft unless put in NavigationPage

$
0
0

The hamburger button of the master detail page is always on the left even I set the FlowDirection to RightToLeft , this happens when the MainPage is set this way in App.xaml.cs:

MainPage = new MasterDetailPage();

The menu itself is on the right:

But I noticed that it works properly when I put it in NavigationPage:

MainPage = new NavigationPage( new MasterDetailPage());

but I have to set the NavigationPage.HasNavigationBar to False, to look normal.
Is there a solution to this problem other than the workaround ?

Mobile App Development

$
0
0

We can develop mobile apps that integrate with any available hardware component embedded in a device. We create responsive, intuitive and innovative mobile apps that help you, your team and your customers more productive and communicative while on the move. In this modern day in age mobile tech needs to be fast and functional in order to offer enough value to its users. We focus strongly on these qualities in our mobile app development to ensure you're given the best possible product to meet your needs.

iOS : ToolbarItems not displaying on root navigation page

$
0
0

Hello all,

I got three toolbaritems in my app which display everywhere on Android.
Prob is on iOS it only shows on pages which are pushed in the navigationPage. When I'm on the root page of the navigation page, they don't display. How to force iOS to show them even if I'm on the root of the navigationPage ?

Thanks.

     var toolbarItem = new ToolbarItem
            {
                Order = ToolbarItemOrder.Secondary,
                Priority = 0,
                Text = "Help"
            };
            var toolbarItem2 = new ToolbarItem
            {
                Order = ToolbarItemOrder.Secondary,
                Priority = 1,
                Text = "Support"
            };
            var homeToolBar = new ToolbarItem
            {
                Order = ToolbarItemOrder.Primary,
                Priority = 0,
                Icon = "ic_home_black_18dp"
            };

WatchOS 5.1 TCP Outgoing connection problem

$
0
0

Hello.

My Watch App call web service on https protocol in Internet.
I have always nw_resolver_create_dns_service_locked error:

WatchKit Extension[326:81502] dnssd_clientstub ConnectToServer: connect()-> No of tries: 1
WatchKit Extension[326:81502] dnssd_clientstub ConnectToServer: connect()-> No of tries: 2
WatchKit Extension[326:81502] dnssd_clientstub ConnectToServer: connect()-> No of tries: 3
WatchKit Extension[326:81502] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:8 Err:-1 Errno:1 Operation not permitted
WatchKit Extension[326:81502] [] nw_resolver_create_dns_service_locked DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)
WatchKit Extension[326:81502] TIC TCP Conn Failed [1:0x1669aaa0]: 10:-72000 Err(-65563)
WatchKit Extension[326:81492] Task . HTTP load failed (error code: -1009 [10:-72000])
WatchKit Extension[326:81492] NSURLConnection finished with error - code -1009

I added to file
com.apple.security.network.client

but I have new error
ApplicationVerificationFailed: Failed to verify code signature of /private/var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.OPGbCB/extracted/Payload/isafereader.app : 0xe8008016 (The executable was signed with invalid entitlements.)
error MT1006: Could not install the application '/Users/dev/Projects/qaz/qaz/bin/iPhone/Release/qaz.app' on the device 'iPhone (Daniel)': Your code signing/provisioning profiles are not correctly configured. Probably you have an entitlement not supported by your current provisioning profile, or your device is not part of the current provisioning profile. Please check the iOS Device Log for details (error: 0xe8008016).

I checked provisioning options on developer.apple.com.
I have all permissions checked.

What am I doing wrong?

CarouselView with previewing side elements (Here is how)

Getting screen contents height

$
0
0

Hello, I am trying to create my own pan and pinch gestures so I can understand how they work, however I am having some problems finding the boundaries for the dragging. I currently use the ScreenHeight and Contents.Height to find boundaries, however I believe having tabs and a navigation bar are affecting my panning, to where I can't pan all the way to the bottom. Is there a way to get the "usable" content heights that the user sees? I don't care for the tabs and navigation.


Statically registering a Broadcast Receiver - A working example

$
0
0

Hello there

I wan't to statically register a Broadcast Receiver and I have followed the guidelines at
https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers

As I understand we do not register the Broadcast Receiver directly in the Android Manifest file, but instead we decorate our receiver as following

[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "com.xamarin.example.TEST" })]
public class MySampleBroadcastReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        Console.WriteLine("Hurray it works"!);
    }
}

Then the receiver should be able to pick up on the following broadcast

Intent message = new Intent("com.xamarin.example.TEST");
SendBroadcast(message);

However I do not receive this intent. I only receive the intent, when I register the receiver within the context as following

RegisterReceiver(new MySampleBroadcastReceiver(), new IntentFilter("com.xamarin.example.TEST"));

Have I misunderstood something or am I missing some steps? Any help would be appreciated.

Why do I need this?
My goal is to launch notifications at particular timestamps defined by the user. I've context-registered a broadcast receiver, that issues a notification, when an intent is received. The Android Alarm Manager is used to broadcast the intent at a particular time.
As the broadcast receiver is context-registered it will not receive intents, when the app has been killed (when the app is swiped in the recent applications menu). I want the notifications to keep coming when the app has been swiped.

Xamarin.Forms Sirikit Implementation.

$
0
0

I need to implement in a Xamarin.Forms Project Sirikit. I have tested sirikit in xamarin.ios only projects and works fine. Cant say the same about Xamarin Forms.

I dont know whats going on because it doesnt even get to the GetHandler function (Im debugging with console.Writeline commands to know if it reaches it). Im thinking, once xamarin.forms is initialized, it cant reach the ios siri intents.

I need help.

Good morning, i can´t resolve Plugin.InputKit error after install it, it appears follow code error:

$
0
0

Can not resolve reference: Plugin.CurrentActivity, referenced by Plugin.InputKit. Please add a NuGet package or assembly reference for Plugin.CurrentActivity, or remove the reference to Plugin.InputKit. SoftcomunaApp.Android

How to reduce space between 2 label on a Grid??

$
0
0

I have a Grid with 2 label and I want minimal space between, but I'm not be able to reduce it.

I've tried RowSpacing="1" but it doesn't work

  <ContentPage.Content>

            <Grid Padding="20, 0, 20, 20" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>


            <Grid Grid.Row="0">
                <Grid RowSpacing="1"> 
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                        <Label Text="FisrtLabel" FontSize="60" HorizontalOptions="Center"  Grid.Row="0" TextColor="Black"/>
                        <Label Text="Second" FontSize="16" HorizontalOptions="Center" Grid.Row="1" TextColor="Black"/>
                </Grid>
            </Grid>

....

How could I fix it!?

Opening a PDF in Default Application

$
0
0

I have followed all the directions for opening a pdf from downloads but I always get an error that it cannot access the file. I have read storage on, how do I start an intent to open the default file handler for a variety of files without some security issue?

Get images to Gallery instantly

$
0
0

Hey guys,

I'm working on a tiny app, which creates images. Most parts are working pretty well, some bugs as usually.
But one thing is making me mad. If I create an Image (JPG) it needs at least 10 Minutes, sometimes a reboot, till the images appears in the gallery.
Did anyone got that problem, and if, how did you solved it?

Here is my code
class savePic { public void Save(string directory, Bitmap bitmap) { int dirLength = directory.Length; for (int i = dirLength; i > 0; i--) { if (directory.Substring((i - 1), 1) == ".") { directory = directory.Substring(0, i - 1) + "_overlay.jpg"; } } var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.Path; var filePath = System.IO.Path.Combine(sdCardPath, directory); var stream = new FileStream(filePath, FileMode.Create); bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); stream.Close(); } }

Regards
Buzz

Firebase console - problem sending test FCM messages

$
0
0

I've posted this on the FCM slack channel, but in the absence of any response so far there, I thought it would be worth trying here!

I'm having problems sending test messages from the console.

I've configured my Xamarin.iOS app, and have done the necessary in the app - it's generating the token when the app is first run.

When I use the FCM Console to send a test message, after I've selected my app, the console says 'This campaign targets 0 app user(s) (0% of potential users).'

When I continue to actually publish the message, it appears in the list of messages but with '0' against Sends. And (of course), it's never received on my device. I'm sending to specific devices by entering the FCM tokens in the 'Test On Device' section.

So it appears that the messages are never being sent!

What am I missing? I've previously sent messages fine for other apps.


removing space between label and a list view.

$
0
0

How do i remove the space between my label and the list view?

Xamarin MvvmCross java.lang.ClassNotFoundException: Didn't find class "Mvx.MvxImageView"

$
0
0

Hi,

My app has started throwing exceptions stating it can't find the Mvx.MvxImageView class. It throws on BindingInflate within the OnCreateView of a MvxFragment. The fragment is for an image in a gallery. The trace and XML is below.

Any ideas why it can't find Mvx.MvxImageView?

XML

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

<Mvx.MvxImageView
class="cirrious.mvvmcross.binding.droid.views.MvxImageView"
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView" />

Exception

08-17 16:28:17.040 E/AndroidRuntime(29309): FATAL EXCEPTION: main
08-17 16:28:17.040 E/AndroidRuntime(29309): Process: ie.myapp.android.app, PID: 29309
08-17 16:28:17.040 E/AndroidRuntime(29309): android.view.InflateException: Binary XML file line #1: Error inflating class Mvx.MvxImageView
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
08-17 16:28:17.040 E/AndroidRuntime(29309): at myapp.mobile.droid.views.fragments.GalleryImageFragment.n_onCreateView(Native Method)
08-17 16:28:17.040 E/AndroidRuntime(29309): at myapp.mobile.droid.views.fragments.GalleryImageFragment.onCreateView(GalleryImageFragment.java:28)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.view.ViewPager.populate(ViewPager.java:1105)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1473)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.View.measure(View.java:17430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.View.measure(View.java:17430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.View.measure(View.java:17430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
08-17 16:28:17.040 E/AndroidRuntime(29309): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:447)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.View.measure(View.java:17430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.View.measure(View.java:17430)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.Choreographer.doFrame(Choreographer.java:550)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.os.Handler.handleCallback(Handler.java:739)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.os.Handler.dispatchMessage(Handler.java:95)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.os.Looper.loop(Looper.java:135)
08-17 16:28:17.040 E/AndroidRuntime(29309): at android.app.ActivityThread.main(ActivityThread.java:5221)
08-17 16:28:17.040 E/AndroidRuntime(29309): at java.lang.reflect.Method.invoke(Native Method)
08-17 16:28:17.040 E/AndroidRuntime(29309): at java.lang.reflect.Method.invoke(Method.java:372)
08-17 16:28:17.040 E/AndroidRuntime(29309): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-17 16:28:17.040 E/AndroidRuntime(29309): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-17 16:28:17.040 E/AndroidRuntime(29309): Caused by: java.lang.ClassNotFoundException: Didn't find class "Mvx.MvxImageView" on path: DexPathList[[zip file "/data/app/ie.myapp.android.app-1/base.apk"],nativeLibraryDirectories=[/data/app/ie.myapp.android.app-1/lib/x86, /vendor/lib, /system/lib]]
08-17 16:28:17.040 E/AndroidRuntime(29309): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-17 16:28:17.040 E/AndroidRuntime(29309): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-17 16:28:17.040 E/AndroidRuntime(29309): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
08-17 16:28:17.040 E/AndroidRuntime(29309): at androi
08-17 16:28:20.605 I/Process (29309): Sending signal. PID: 29309 SIG: 9

What is the best place to pre-process data before any UI is initialized?

$
0
0

I want to process the data in a database before any UI pulls the data from it through View Model. Since async / await operations involved, which is the best place to pre-process data?

I find doing it in OnAppearing() is not meeting my requirement and I have to pull to refresh the ListView.

Label visibility true when entry text property is not empty

$
0
0

Hello Guy's

      I have a create application but i am facing a issue.
      I want to label visibility true when entry text property is not empty and when entry text property not empty then label visibility false.
      I want to do this thing only Xaml page not Cs. page.

         <StackLayout  Grid.Row="1" Orientation="Vertical" BackgroundColor="Transparent" Spacing="10">
                <Label x:Name="lblUserName" Text="User ID" FontSize="Medium" TextColor="White" />
               <Entry x:Name="enrtyUserName" Placeholder="User ID" FontSize="Medium" PlaceholderColor="Gray" BackgroundColor="White" />
        </StackLayout>

Is it possible in xaml coding use like value converter or triggers.

Thanks in advance

[XAMARIN FORMS] problem of the link between my xaml view (with a picker) and the viewmodel

$
0
0

Hello everyone,

I have a small problem, I explain myself:

here's what I did, I have a page with buttons (with different values) and a picker (see xaml code), when the user clicks on a button, normally the picker selection list proposes things that are linked to the value of my button through lists (see my view model code). Except it doesn't work!

In my opinion it is because of the static type that is on some of my lists and methods. So my picker which has a binding on one of my lists does not display my selection because it cannot access my list because it is in static and not a constructor (in which I call the element of my binding).

Do you have a solution for me?

If you can't understand me, don't hesitate to ask me questions?

you will find the different files with my code below.

Sincerely
Camille

xaml code :

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="PolQual.Views.StatementReferencielPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:PolQual.Views"
    xmlns:viewModels="clr-namespace:PolQual.ViewModels;assembly=PolQual"
    Title="Accueil">

    <ContentPage.BindingContext>
        <viewModels:StatementReferencielPageModel />
    </ContentPage.BindingContext>

    <ContentPage.Content>

        <StackLayout>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="10*" />
                    <RowDefinition Height="15*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100*" />
                </Grid.ColumnDefinitions>

                <Label
                    Grid.Row="0"
                    Grid.Column="0"
                    FontSize="25"
                    HorizontalOptions="Center"
                    Text="Information sur le relevé référenciel" />

            </Grid>

            <ScrollView>
                <Grid x:Name="gridLayout" />
            </ScrollView>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="8*" />
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="6*" />
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="6*" />
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="6*" />
                    <RowDefinition Height="5*" />
                    <RowDefinition Height="6*" />
                    <RowDefinition Height="1*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="25*" />
                    <ColumnDefinition Width="50*" />
                    <ColumnDefinition Width="25*" />
                </Grid.ColumnDefinitions>

                <Label
                    Grid.Row="1"
                    Grid.Column="1"
                    FontSize="15"
                    Text="Veuillez sélectioner le secteur :" />

                <Picker
                    x:Name="PickerSectorsLists"
                    Title="Sélectionner votre secteur"
                    Grid.Row="2"
                    Grid.Column="1"
                    ItemDisplayBinding="{Binding Value}"
                    ItemsSource="{Binding SectorsFindLists}"
                    SelectedItem="{Binding SelectedSector}" />

                <Label
                    Grid.Row="4"
                    Grid.Column="1"
                    FontSize="15"
                    Text="{Binding ShowHouseholdTrash}" />

                <Switch
                    x:Name="SwitchHousehodTrash"
                    Grid.Row="5"
                    Grid.Column="1"
                    HorizontalOptions="Start"
                    IsToggled="{Binding HouseholdTrash}" />

                <Label
                    Grid.Row="6"
                    Grid.Column="1"
                    FontSize="15"
                    Text="{Binding ShowBoxboard}" />

                <Switch
                    x:Name="SwitchBoxboard"
                    Grid.Row="7"
                    Grid.Column="1"
                    HorizontalOptions="Start"
                    IsToggled="{Binding Boxboard}" />

                <Label
                    Grid.Row="8"
                    Grid.Column="1"
                    FontSize="15"
                    Text="{Binding ShowGlass}" />

                <Switch
                    x:Name="SwitchGlass"
                    Grid.Row="9"
                    Grid.Column="1"
                    HorizontalOptions="Start"
                    IsToggled="{Binding Glass}" />

                <Button
                    Grid.Row="11"
                    Grid.Column="1"
                    BackgroundColor="#2196f3"
                    Clicked="GoToAssesmentGrid"
                    FontSize="20"
                    Text="Valider les informations"
                    TextColor="White" />

            </Grid>

        </StackLayout>

    </ContentPage.Content>
</ContentPage>

Behind code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using PolQual.ViewModels;

namespace PolQual.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class StatementReferencielPage : ContentPage
    {
        public StatementReferencielPage()
        {
            InitializeComponent ();
            BindingContext = new StatementReferencielPageModel();
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(40) });
            //collmun
            gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(25, GridUnitType.Star) });
            gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) });
            gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(25, GridUnitType.Star) });

            var PolesListsIndex = 0;

            for (int columnIndex = 1; columnIndex < 2; columnIndex++)
            {
                for (int rowIndex = 0; rowIndex < 7; rowIndex++)
                {
                    if (PolesListsIndex >= StatementReferencielPageModel.PolesLists.Count<Pole>())
                    {
                        return;
                    }
                    var poles = StatementReferencielPageModel.PolesLists[PolesListsIndex];
                    PolesListsIndex += 1;

                    var button = new Button()
                    {                   
                        Text = poles.Name,
                        BackgroundColor = Color.FromHex(poles.Color),
                        HorizontalOptions = LayoutOptions.Center,
                        VerticalOptions = LayoutOptions.Center,
                        WidthRequest = 280,
                    };
                    string request = StatementReferencielPageModel.PolesLists[rowIndex].Name;
                    button.Clicked += delegate { MaFunction(request); };// anonymous method
                    gridLayout.Children.Add(button, columnIndex, rowIndex);  

                }
            }
        }

        public static void MaFunction(string polename)
        {
           StatementReferencielPageModel.FindPoleName(polename);
        }

        public void GoToAssesmentGrid(object sender, System.EventArgs e)
        {
            if (PickerSectorsLists.SelectedIndex == -1) 
            {
                DisplayAlert("Erreur de saisie", "Veuillez séléctioner un secteur svp! ", "D'accord");
            }
            else
            {
                var page = new AssesmentGridPage();
                Navigation.PushAsync(page);
            }
         }
    }
}

view Model code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using Xamarin.Forms;
using PolQual.Views;

namespace PolQual.ViewModels
{
    public class StatementReferencielPageModel : INotifyPropertyChanged
    {
        private static List<Sector> _sectorsLists;
        public static List<Sector> SectorsLists { get => _sectorsLists; set => _sectorsLists = value; }

        private readonly List<Sector> sectorsFindLists;
        private static List<Sector> _sectorsFindLists;
        public static List<Sector> SectorsFindLists { get => _sectorsFindLists; set => _sectorsFindLists = value; }

        private static List<Pole> _polesLists;
        public static List<Pole> PolesLists { get => _polesLists; set => _polesLists = value; }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged([CallerMemberName] string propertyname = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
        }

        private bool _boxboard { get; set; }
        public bool Boxboard
        {
            get { return _boxboard; }
            set
            {
                _boxboard = value;
                OnPropertyChanged();
                OnPropertyChanged(nameof(ShowBoxboard));
            }
        }

        private bool _glass { get; set; }
        public bool Glass
        {
            get { return _glass; }
            set
            {
                _glass = value;
                OnPropertyChanged();
                OnPropertyChanged(nameof(ShowGlass));
            }
        }

        private bool _householdTrash { get; set; }
        public bool HouseholdTrash
        {
            get { return _householdTrash; }
            set
            {
                _householdTrash = value;
                OnPropertyChanged();
                OnPropertyChanged(nameof(ShowHouseholdTrash));
            }
        }

        private Sector _selectedSector { get; set; }
        public Sector SelectedSector
        {
            get { return _selectedSector; }
            set
            {
                if (_selectedSector != value)
                {
                    _selectedSector = value;
                    // que faire quand l'élèment est sélectionné !
                }
            }
        }

        public StatementReferencielPageModel()
        {
            SectorsLists = GetSectors().OrderBy(t => t.Key).ToList();
            SectorsFindLists = GetSectors().OrderBy(t => t.Key).ToList();
            PolesLists = GetPoles().OrderBy(t => t.Key).ToList();
        }

        public List<Sector> GetSectors()
        {
            var Sectors = new List<Sector>()
            {
                //Erdre et cens
                new Sector() { Key = 0, Value = "Sautron", PoleName="Erdre et cens" },
                new Sector() { Key = 1, Value = "Orvault", PoleName="Erdre et cens" },
                new Sector() { Key = 2, Value = "Nantes Nord", PoleName="Erdre et cens" },
                new Sector() { Key = 3, Value = "La-Chapelle-Sur-Erdre", PoleName="Erdre et cens" },
                // Erdre et Loire
                new Sector() { Key = 4, Value = "Mauves-Sur-Loire", PoleName="Erdre et Loire" },
                new Sector() { Key = 5, Value = "Carquefou", PoleName="Erdre et Loire" },
                new Sector() { Key = 6, Value = "Thouré sur Loire", PoleName="Erdre et Loire" },
                new Sector() { Key = 7, Value = "Sainte Luce sur Loire", PoleName="Erdre et Loire" },
                new Sector() { Key = 8, Value = "Nantes Erdre", PoleName="Erdre et Loire" },
                new Sector() { Key = 9, Value = "Doulon", PoleName="Erdre et Loire" },
                //Loire-Sèvre et Vignoble
                new Sector() { Key = 10, Value = "Rezé", PoleName="Loire-Sèvre et Vignoble" },
                new Sector() { Key = 11, Value = "Les Sornières", PoleName="Loire-Sèvre et Vignoble" },
                new Sector() { Key = 12, Value = "Vertou", PoleName="Loire-Sèvre et Vignoble" },
                new Sector() { Key = 13, Value = "Saint Sébastien sur Loire", PoleName="Loire-Sèvre et Vignoble" },
                new Sector() { Key = 14, Value = "Base Goulaine", PoleName="Loire-Sèvre et Vignoble" },
                new Sector() { Key = 15, Value = "Nantes sud", PoleName="Loire-Sèvre et Vignoble" },
                //Sud-Ouest
                new Sector() { Key = 16, Value = "Bouchenais", PoleName="Sud-Ouest" },
                new Sector() { Key = 17, Value = "Saint-Aignan-Grandlieu", PoleName="Sud-Ouest" },
                new Sector() { Key = 18, Value = "Bouaye", PoleName="Sud-Ouest" },
                new Sector() { Key = 19, Value = "Saint-Leger-Les-Vignes", PoleName="Sud-Ouest" },
                new Sector() { Key = 20, Value = "Brains", PoleName="Sud-Ouest" },
                new Sector() { Key = 21, Value = "La-Montagne", PoleName="Sud-Ouest" },
                new Sector() { Key = 22, Value = "Saint-Jean-De-Boiseau", PoleName="Sud-Ouest" },
                new Sector() { Key = 23, Value = "Le Pellerin", PoleName="Sud-Ouest" },
                //Loire-Chézine
                new Sector() { Key = 24, Value = "Couëron", PoleName="Loire-Chézine" },
                new Sector() { Key = 25, Value = "Saint-Herblain", PoleName="Loire-Chézine" },
                new Sector() { Key = 26, Value = "Indre", PoleName="Loire-Chézine" },
                //Nantes-Ouest
                new Sector() { Key = 27, Value = "Bellevue-Chantenay-Sainte-Anne", PoleName="Nantes-Ouest" },
                new Sector() { Key = 28, Value = "Dervallière-Zola", PoleName="Nantes-Ouest" },
                new Sector() { Key = 29, Value = "Breil-Barberie", PoleName="Nantes-Ouest" },
                new Sector() { Key = 30, Value = "Hauts Pavés Saint Félix", PoleName="Nantes-Ouest" },
                //Nantes-Loire
                new Sector() { Key = 31, Value = "Malakof-Saint-Donatien", PoleName="Nantes-Loire" },
                new Sector() { Key = 32, Value = "Centre Ville", PoleName="Nantes-Loire" },
                new Sector() { Key = 33, Value = "île de Nantes", PoleName="Nantes-Loire" },

            };
            return Sectors;
        }

        public List<Pole> GetPoles()
        {
            var Poles = new List<Pole>()
            {
                new Pole { Key = 1, Name = "Erdre et Cens", Color = "ffccd5"},
                new Pole { Key = 2, Name = "Erdre et Loire", Color = "ff4d4d"},
                new Pole { Key = 3, Name = "Loire-Sèvre et vignoble", Color = "ff9933"},
                new Pole { Key = 4, Name = "Sud-Ouest", Color = "bfbfbf"},
                new Pole { Key = 5, Name = "Loire-chézine", Color = "ffff4d"},
                new Pole { Key = 6, Name = "Nantes-Ouest", Color = "3385ff"},
                new Pole { Key = 7, Name = "Nantes-Loire", Color = "53c653"},
            };
            return Poles;
        }

        public static void FindPoleName(string polename)
        {
            for (int search = 0; search < SectorsLists.Count(); search++)
            {
                if (SectorsLists[search].PoleName == polename)
                {
                    SectorsFindLists.Add(new Sector() {Key = search, Value = SectorsLists[search].Value, PoleName = polename });
                }
            }
        }

        public string ShowBoxboard
        {
            get
            {
                return $"{(_boxboard ? "Jour de collecte des cartons : oui " : "Jour de collecte des cartons : non")}";
            }
        }

        public string ShowGlass
        {
            get
            {
                return $"{(_glass ? "Jour de collecte du verre : oui " : "Jour de collecte du verre : non")}";
            }
        }

        public string ShowHouseholdTrash
        {
            get
            {
                return $"{(_householdTrash ? "Jour de collecte des Ordure ménagère : oui " : "Jour de collecte des Ordure ménagère : non")}";
            }
        }
    }

    public class Sector
    {
        private int _key;
        public int Key { get => _key; set => _key = value; }

        private string _value;
        public string Value { get => _value; set => _value = value; }

        private string _poleName;
        public string PoleName { get => _poleName; set => _poleName = value; }
    }

    public class Pole
    {
        private int _key;
        public int Key { get => _key; set => _key = value; }

        private string _color;
        public string Color { get => _color; set => _color = value; }

        private string _name;
        public string Name { get => _name; set => _name = value; }
    }
}
Viewing all 204402 articles
Browse latest View live


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