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

Calling A Content Page

$
0
0

Good day,
How can I call another content page by pressing a button on the main content page.
I appreciate your kind help.

Thanks/Regards.


PushModalAsync vs PushAsync

$
0
0

I am making my first forms app since Evolve.
I have a tableview up and working okay, but when I select one of the items I want to open a new form page

I tried this one, and it works well in android because I can use the back button
await this.Navigation.PushAsync(new InfragisticReportViewer());

But when I use it in ios there is no navigation bar so there is no way to go back to the tableview

I found some samples using PushAsync
so I tried this
await this.Navigation.PushAsync(new InfragisticReportViewer());

But this just blows up:
Mono.Debugger.Soft.AbsentInformationException: Debug information is not available for this frame.
at Mono.Debugger.Soft.VirtualMachine.ErrorHandler(Object sender, ErrorHandlerEventArgs args)
at Mono.Debugger.Soft.Connection.SendReceive(CommandSet command_set, Int32 command, PacketWriter packet)
at Mono.Debugger.Soft.Connection.StackFrame_GetThis(Int64 thread_id, Int64 id)
at Mono.Debugger.Soft.StackFrame.GetThis()

Am I doing this right? Or maybe there is a basic example of opening a new form after selecting a grid item.

Ed,

Call Navigation.PushAsync from ViewModel

$
0
0

Hello,

I want to push a new page from a viewModel.

Can I call this method from outside the page?

Thanks in advance.
Mostafa

Navigation in ViewModel

$
0
0

Hello,
I'm new to MVVM/XAML and want to implement navigation in my App.

In the View I have:

        public LoginPageX()
        {
            InitializeComponent();
            BindingContext = new LoginViewModel(Navigation);
        }

And in my ViewModel:

        public class LoginViewModel
        {
            public Command LoginCommand { get; set; }
            INavigation navigation;

            public LoginViewModel(INavigation loginPageNav)
            {
                navigation = loginPageNav;
                LoginCommand = new Command(async () => await OfflineButton());
            }


            public async Task OfflineButton()
            {
                navigation.InsertPageBefore(new MainPageX(), LoginPageX);
                await navigation.PopAsync();
            }
        }

I'm a little confused about how to navigation.InsertPageBefore(new MainPageX(), what page?);

CircleImage add assembly to xaml

Entry focus on appearing first page [LoginPage]

$
0
0

Hi,

I'm having issues with focussing an entry when the first page (when launching the app) appears. I use the following code:

protected override void OnAppearing()
        {
            base.OnAppearing();
            string username = Application.Current.Properties["Username"].ToString();
            if (!String.IsNullOrEmpty(username))
            {
                usernameEntry.Text = username;
                if (passwordEntry1.IsFocused == false)
                {
                    passwordEntry1.Focus();
                }                    

            } else
            {
                usernameEntry.Focus();
            }
        } 

This page contains a button 'Forgot password' which navigates to a navigation page. If I navigate from that page back to the LoginPage, the entry does get focussed. I've read some things about Xamarin having to render the entry's and that that has to be done before it can get focussed, which sounds obvious to me. Anyone have a clue on how to fix this issue?

Greetings,

ONE_Developer

After creating nuget package dependency service not working in Xamarin forms project.

$
0
0

hi,

I have created a xamarin app to play audio from project folder and created app using dependency service play the audio file then it's working fine.
And I have create nuget package using the same source code but dependency service not working via configuring the created nuget package i have attached my entire source here.Any one kindly review it and help me how fix this.

use below link to download the file

Create a library to play the audio using dependency service. find the below link to download the source

https://drive.google.com/open?id=1amiuXEZ_QvxRHD4TmzEFKkPTs8Z-5e1O

sample create by using nuget package what i have developed.find the below link to download the source

https://drive.google.com/open?id=1I62ubkfnAMPDJLwpK5ZDRhlXg5abcIRS

thanks in advance

How to make visible checkbox on menu item

$
0
0
Hello everyone, my name is Taniguchi and i am using xamarin forms and i put checkboxes on my list view but i set the visibility as false i would like that my checkbox only appear when menu item is showm how can i do that or can i put checkbox on context action?

Xamarin Forms: How to clear the read push notification using the notification id

$
0
0

I have implemented push notifications for my chat application using FCM. My application has groups same like WhatsApp groups. New notifications will receive when chatting inside a group. I need to clear the notifications which are already read.

I found a blog for this feature. But it is not working for me. My codes are added below:

In PCL:

public interface IPushCancel
    {
        void CancelPush(long id);
    }

In Android:

public class PushCancelService : IPushCancel
    {
        public void CancelPush(long id)
        {
            var intent = CreateIntent(id);
            var pendingIntent = PendingIntent.GetBroadcast(Android.App.Application.Context, (int)id, intent, PendingIntentFlags.CancelCurrent);
            var alarmManager = GetAlarmManager();
            alarmManager.Cancel(pendingIntent);
            var notificationManager = NotificationManagerCompat.From(Android.App.Application.Context);
            notificationManager.CancelAll();

        }
        private AlarmManager GetAlarmManager()
        {
            var alarmManager = Android.App.Application.Context.GetSystemService(Context.AlarmService) as AlarmManager;
            return alarmManager;
        }

        private Intent CreateIntent(long id)
        {
            return new Intent(Android.App.Application.Context, typeof(MainActivity /*"Here we have to put GCM Listener class"*/))
              .SetAction("LocalNotifierIntent" + id);
        }
    }

In IOS:

public class PushCancelService : IPushCancel
    {
        private const string NotificationKey = "LocalNotificationKey";
        public void CancelPush(long id)
        {
            UIApplication.SharedApplication.CancelAllLocalNotifications();
            var notifications = UIApplication.SharedApplication.ScheduledLocalNotifications;
            var notification = notifications.Where(n => n.UserInfo.ContainsKey(NSObject.FromObject(NotificationKey))).FirstOrDefault(n => n.UserInfo[NotificationKey].Equals(NSObject.FromObject(id)));
            UIApplication.SharedApplication.CancelAllLocalNotifications();
            if (notification != null)
            {
                UIApplication.SharedApplication.CancelLocalNotification(notification);
                UIApplication.SharedApplication.CancelAllLocalNotifications();
            }
        }
    }

Notification ID

In MainActivity I am passing the notification_id like below:

public override void OnMessageReceived(RemoteMessage message)
    {
        base.OnMessageReceived(message);
        var myData = JsonConvert.DeserializeObject<List<webContentList>>(webContentList);
        string webcontentId = myData[0].webContentDefinitionId.ToString();
        try
        {
            //passing groupid and notification id with a blank space
            MessagingCenter.Send<object, string>(this, "webcontentId", webcontentId + " " + message.MessageId);
        }
        catch (Exception exc)
        {
            Console.WriteLine("exception:>>" + exc);
        }

    }
    catch (Exception ex)
    {
        Console.WriteLine("Error:>>" + ex);
    }
}

In IOS I am passing the notification_id like below from AppDelegate.cs:

public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {
            var myData = JsonConvert.DeserializeObject<List<webContentList>>(userInfo[new NSString("webContentList")] as NSString);
            string notificationId = (userInfo[new NSString("gcm.message_id")] as NSString).ToString();

            if (UIApplication.SharedApplication.ApplicationState.Equals(UIApplicationState.Active))
            {
                //App is in foreground. Act on it.
                if (myData != null)
                {
                    string webcontentId = myData[0].webContentDefinitionId.ToString();
                    try
                    {
                        //Passing notification id and group id from here through MessagingCenter
                        MessagingCenter.Send<object, string>(this, "webcontentId", webcontentId + " " + notificationId);
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine("messagecenterexception:>>" + exc);
                    }
                }
            }
            else
            {
                MessagingCenter.Send<object, List<webContentList>>(this, "messagedata", myData);
            }
        }

Finally, I am calling the notification clear DependencyService from my group page like below:

MessagingCenter.Subscribe<object, string>(this, "webcontentId", (object obj, string notifWebcontentId) => {
                if (notifWebcontentId != "")
                {
                    string[] multiArray = notifWebcontentId.Split(' ');
                    //Checking foreground group id and notification group id are same
                    if (multiArray[0] == webcontentId)
                    {
                        DependencyService.Get<IPushCancel>().CancelPush(long.Parse(multiArray[1]));
                        RefreshMessageList();
                    }
                }
            });

Observations

IOS

No error or exception is showing in ios, but code execution is not going inside of the following `if.

if (notification != null)
            {
                UIApplication.SharedApplication.CancelLocalNotification(notification);
                UIApplication.SharedApplication.CancelAllLocalNotifications();
            }

Android

Getting TargetInvocationException when sending notification id from Mainactitivity.

Exception Details:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.

Please help me to solve implement this feature. I need to clear the read message notifications automatically. Otherwise, the user will struggle by a lot of notifications.

ListView issue on Items offset screen (Scroll)

$
0
0

Hi there guys, a newbie on Xamarin Forms here.
I´ll try to explain my best, I prepared some images to clarify this doubt.

I have an app where you have a list to choose items (products), by clicking on an item takes you to the next list (brands), again a click takes you to the different elements of that product and brand, to end in a description of the chosen product.
It reads an XLS Excel file to get the info with NPOI.

and all this works perfectly for the elements that fit on the screen at that moment

but if I scroll to get ( Itemtapped) items on the list that are offset the screen (scrolling to reach them), a very curious thing happens, the last option to choose the specific item does not appear, the list is blank, but the "buttons" are there, so if I click on an empty button, it takes me to the correct description

I mean, the code internally works correctly, but the text is not showed on the screen (sometimes it show something, others none, is a very random issue, but always happens for the items offset screen).

Details: if I change in the excel database the position of the sheets, so for example, the items that were previously under, are now up, it works nicely, but now, again, the items that left offscreen are the issue ones XD, is very curious, because the code works, is not a fault on some "extrange format" in the excel sheets. Before posting here I tried every crazy thing I thought of it.

Are there any know issue with ListView and Itemtapped related (on a StackLayout), with items offset the screen?

This is my XAML code.

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

<StackLayout >
    <!-- Place new controls here -->
        <StackLayout >
        <Button Text="PRESUP DE ENMAR" 
                    Clicked="OnButtonMarcos"
                    HeightRequest="35" 
                    FontSize="12" 
                    TextColor="White" 
                    BackgroundColor= "#8e8e8e"
                    BorderRadius="15"
                    BorderColor="Black"
                    BorderWidth="2" />
    </StackLayout>


    <Grid>
        <Grid.ColumnDefinitions >
            <ColumnDefinition />
            <ColumnDefinition  />
        </Grid.ColumnDefinitions>

        <StackLayout  Grid.Column="0" >
            <Button Text="RESET" 
                    Clicked="OnButtonReset" 
                    HeightRequest="35" 
                    FontSize="12" 
                    TextColor="White" 
                    BackgroundColor= "#5e5e5e"
                    BorderRadius="15"
                    BorderColor="Black"
                    BorderWidth="2"/>
        </StackLayout>

        <StackLayout Grid.Column="1">
            <Button Text="MIS DATOS" 
                    Clicked="OnButtonMisDatos" 
                    HeightRequest="35" 
                    FontSize="12" 
                    TextColor="White" 
                    BackgroundColor= "#5e5e5e"
                    BorderRadius="15"
                    BorderColor="Black"
                    BorderWidth="2"/>
        </StackLayout>

    </Grid>


    <StackLayout Padding="0,10,0,10">
        <BoxView HeightRequest="5" BackgroundColor="Accent" />
    </StackLayout>


   <ListView  HasUnevenRows="True"  x:Name="myListView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>

                   <StackLayout VerticalOptions="Center" HorizontalOptions="Center" Grid.Column="0">
                        <Label FontSize="20"  Text="{Binding Etiquetas}" TextColor="Black" HorizontalOptions="Center"/>

                        <StackLayout>
                       <BoxView HeightRequest="2" WidthRequest="500" BackgroundColor="Green"/>
                        </StackLayout>

                    </StackLayout>

                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</StackLayout>

Hope I explained well
Thanks guys!!!!

Clear TimePicker or DatePicker on android when navigating on lifecycle events

$
0
0

Hi all,

I'm running into an issue on android where our TimePicker and DatePicker stay visible when we navigate OnPause(). We need to redirect our users back to the login screen when they background the application, but if the TimePicker or DatePicker is active when they do this it stays on the screen. It appears above the login screen and pressing cancel or ok crashes the app.

We are hooking into the native android lifecycle events (not just using Xamarins built in hooks) and we redirect OnResume(). I've tested this in a barebones app though and it still happens OnPause().

Here is our TimePicker:

<TimePicker x:Name="VitalTimePicker" HorizontalOptions="Fill" VerticalOptions="Fill" IsVisible="false" PropertyChanged="OnTimePickerPropertyChanged"/>

And here is an example of redirecting from the barebones app I made:

protected override void OnSleep()
        {
            App.Current.MainPage = new NavigationPage(new NotesPage());
        }

Anyone have any ideas?

Assets files write/read

$
0
0

Hi,

I have a "itinerary.html" file which is Assets/Content folder inside the Droid project. My problem is that I cannot find a proper way of writing that file and then be able to access that file in order to be used as a URI for an WebView page.

I will attach part of my code here:

public Itinerary(string htmlBody)
{

    string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "itinerary.html");
    File.WriteAllText(fileName, htmlBody);

    MyWebView.Uri = "itinerary.html";
}

in the first 2 lines from this constructor I am trying to overwrite what is in "itinerary.html" file and then I assign that file to the URI (The file exist in the folder) but when the WebView is trying to show that page it will show an empty page because the content has not been actually overwritten.

Does anybody has encountered this problem ?

Thanks

Shell Styling for Title Bar not working

$
0
0

I generated a new shell app in Visual Studio Community 2019, which gave me an App.Shell.xaml file containing some styling, like this:

<ResourceDictionary>
        <Style x:Key="ShellStyle" TargetType="Element">
            <Setter Property="Shell.TitleColor" Value="Fuchsia" />
            <Setter Property="Shell.BackgroundColor" Value="Green" />
            <Setter Property="Shell.ForegroundColor" Value="Yellow" />
            <Setter Property="Shell.TitleColor" Value="Red" />
            <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
            <Setter Property="Shell.UnselectedColor" Value="Grey" />
            <Setter Property="Shell.TabBarBackgroundColor" Value="Blue" />
            <Setter Property="Shell.TabBarForegroundColor" Value="Indigo" />
            <Setter Property="Shell.TabBarUnselectedColor" Value="Lime" />
            <Setter Property="Shell.TabBarTitleColor" Value="Teal" />
        </Style>
        <Style TargetType="ShellItem" BasedOn="{StaticResource ShellStyle}" />
    </ResourceDictionary>

Those weren't the default colours by the way...

Anyway, none of those styles were being applied to the shell items (the bar right at the top of the app, or the tab bar at the bottom. The title is displayed at the top, and the tabs at the bottom, they just didn't have the above styling.

I managed to fix the tab bar, by adding some new styles to the resource dictionary:

<Style x:Key="TabStyle" TargetType="TabBar">
    <Setter Property="Shell.TabBarBackgroundColor" Value="Teal" />
    <Setter Property="Shell.TabBarUnselectedColor" Value="Silver" />
    <Setter Property="Shell.TabBarTitleColor" Value="Fuchsia" />
</Style>

Then I just applied the style to the TabBar in the usual way:

<TabBar Style="{StaticResource TabStyle}">
    ...
</TabBar>

This works perfectly and the styling is applied to the tab bar at the bottom. Unfortunately, I cannot get any styling to work for the top bar of the app. None of the styles like Shell.TitleColor or Shell.BackgroundColor have any effect on the app whatsoever, and unlike with the TabBar, I don't have a <TitleBar> or any element to manually add styles to.

I did think about hiding the shell top bar, and using my own one instead, but I guess with this approach, I would then have to handle navigating back to previous pages.

What's the recommendation here? Why isn't the shell styling working as this page says it should: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/configuration#set-page-colors ??

I'm using Xamarin Forms 4.1.0.581479

How can i access to SIM card storage where the certificates are installed?

$
0
0

Hi,
I want to access to sim card datas. You can know that e-signature method recently appeared in mobile certificate. Installing certificate on sim card. Now I need to access the sim card with the mobile application and get the certificate there. Does anyone know about this topic?

Bind background color of DataGrid's Row Using Grial UI kit in Xamarin

$
0
0

Hello Developers

I am using Grial Kit UI in xamarin and implement a DataGrid Page, But i want to bind background color of each row in Grid data.

This is my UI Code

 <ContentPage.Resources>
        </ResourceDictionary>
<!--     Grid Styles -->
            <Style TargetType="grial:DataGrid">
                    <Setter Property="SelectedBackgroundColor" Value="#20BFE1FF" />
                    <Setter Property="HeaderRowBackgroundColor" Value="{ DynamicResource DataGridHeaderRowBackgroundColor }" />
                    <Setter Property="BackgroundColor" Value="{ DynamicResource DataGridBackgroundColor }" />
                    <Setter Property="GridSeparatorVisibility" Value="None" />
                    <Setter Property="HeaderSeparatorVisibility" Value="None" />
          </Style>

           <!-- Column Styles -->
            <Style x:Key="BaseColumn" TargetType="grial:DataGridColumn">
                    <Setter Property="IsSortable" Value="True" />
                    <Setter Property="SortIconsFontFamily" Value="{StaticResource IconsFontFamily}" />

                    <Setter Property="ColumnWidth" Value="0.1*" />
                    <Setter Property="HeaderTextColor" Value="{ DynamicResource DataGridHeaderTextColor }" />
                    <Setter Property="HeaderTextAlignment" Value="Center" />
                    <Setter Property="HeaderFontSize" Value="14" />
                    <Setter Property="HeaderFontFamily" Value="{ StaticResource AppBoldFontFamily }" />
                    <Setter Property="CellTextColor" Value="{ DynamicResource DataGridCellTextColor }" />
                    <Setter Property="CellPadding" Value="14" />
                    <Setter Property="CellFontSize" Value="14" />
                    <Setter Property="CellTextAlignment" Value="Center" />
                    <Setter Property="CellVerticalAlignment" Value="Center" />
                    <Setter Property="HeaderPadding" Value="4,14" />
           </Style>

       <Style x:Key="NC_Audit_Column" TargetType="grial:DataGridColumn" BasedOn="{StaticResource BaseColumn}">
                    <Setter Property="BindingPath" Value="NON_COMPLY_AUDIT" />
                   <Setter Property="HeaderText" Value="AUDIT" />
            </Style>
            <Style x:Key="NC_Score_Column" TargetType="grial:DataGridColumn" BasedOn="{StaticResource BaseColumn}">
                   <Setter Property="ColumnWidth" Value="75" />
                   <Setter Property="BindingPath" Value="NON_COMPLY_SCORE" />
                   <Setter Property="HeaderText" Value="SCORE" />
            </Style>
        </ResourceDictionary>
 <ContentPage.Resources>

<ContentPage.Content>
    <grial:DataGrid SelectionMode="Row" ItemsSource="{ Binding ItemList}">
          <grial:DataGrid.ColumnDefinitions>
                  <grial:DataGridColumn Style="{ StaticResource NC_Name_Column}" />
                  <grial:DataGridColumn Style="{ StaticResource NC_Score_Column}" />
            </grial:DataGrid.ColumnDefinitions>
      </grial:DataGrid>
</ContentPage.Content>

How can bind background Color in each row and i am passing color field in model

public string Row_BgColor {get; set;}

Thanks


Google Play Upload APK To Alpha Release Track : Google UploadCertificate

$
0
0

Hi, please help if you can. While uploading an APK to the Alpha track I get this issue. I chose to use the Google Play upload certificate but I do not know how to apply it to my APK. Could you please help me understand 1) How to use the Google upload certificate and apply it to my APK as part of the Visual Studio Archive process? 2) If I should be using the OAUTH approach with an id and secret? I am a bit stuck and so far no reply from Google Support.

Pre-Release: Xamarin.Forms 4.2.0-pre1

$
0
0

We've published the 4.2.0-pre1 pre-release of Xamarin.Forms on NuGet; be sure to include pre-releases in your NuGet Package Manager in order to make the package visible. If you encounter any issues or have any feedback to provide, please visit GitHub.

Read the full release notes here.

Notable Additions

  • Shell Lifecycle (PR)
  • Switch ThumbColor (PR)
  • Color.ToHex() (PR)
  • FontImage Markup Extension for FontImageSource (PR)

Additional enhancements for Tizen are featured, as well:

  • Add CheckBox (PR), with Visual support (PR)
  • Support to TabbedPage.BarTextColor, SelctedTabColor, UnselecedTabColor (PR)

Regarding CollectionView

Our original roadmap listed the new CollectionView for official release in Xamarin.Forms 4.2. However, we have determined that it will maintain the Experimental flag for this release. Your feedback during the CollectionView Challenge was important in highlighting the features you need most; in this case, pull-to-refresh and header/footer templates were two of your top wants, among others. Although its development has come a long way, we want to make sure you have the best possible experience when using CollectionView at the time the Experimental flag is removed, which has led us to make this decision. Please continue to test it out if you have the time and let us know what you think. You can read the official spec here.

For more information, you can also read the current docs as well as the original blog post. The 4.2 release includes some bug fixes as well as fuller functionality including grouping on iOS (PR).

Google Play Upload APK To Alpha Release Track : Privacy Permission 'android.permission.Camera'

$
0
0

Hi,
when uploading APK to the Google Play Alpha track I get an error (see below) saying that I need to set a Camera privacy policy. I have the privacy policy set in the AndroidManifest.xml (see below). Is there somewhere else I should be setting the permission? The upload passes on all the other privacy settings. Very odd.

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

















CollectionView not firing SelectionChangedCommand

$
0
0

I am using FreshMVVM to bind my view models to my views, and all commanding has worked great so far. However, I am not able to get the SelectionChangedCommand to fire when I change the selection of a CollectionView.

Full source code can be found here

Here is my XAML...

<StackLayout>
    <CollectionView SelectionMode="Single"
                    ItemsSource="{Binding Tags}"
                    SelectedItem="{Binding SelectedTag, Mode=TwoWay}"
                    SelectionChangedCommand="{Binding SelectedTagChangedCommand}">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <StackLayout>
                    <Label Text="{Binding .}" />
                </StackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</StackLayout>

And the page model...

public class MainPageModel : FreshBasePageModel
{
    public override void Init(object initData)
    {
        Tags = new ObservableCollection<string>() { "A", "B", "C" };
        SelectedTag = "B";

        base.Init(initData);
    }

    public ObservableCollection<string> Tags { get; set; }

    public string SelectedTag { get; set; }

    public Command SelectedTagChangedCommand
    {
        get
        {
            return new Command(() =>
            {
                   // ****** 
                   // ****** this is never called
                   // ****** 
            });
        }
    }
}

Can anyone see the issue here?

TabbedPage Bind Children to ViewModel

$
0
0

Hi,

Is there any way to bind children to variable in ViewModel?

Viewing all 89864 articles
Browse latest View live


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