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

System.Runtime you may need to supply runtime policy?


How to show Confirmation Alert dialog before popping a Page in Xamarin.Forms ?

$
0
0

I am developing a cross platform application using Xamarin.Forms.
I have two pages page1 and page2.
When moving from page2 to page1, using Navigation.PopAsync, I need to show an alert dialog to let the user confirm the action. Only after the user confirms, I need to pop the page.
I need to trap the actions of both the 'Home' button as well as the 'Back' button in android.

How can this be done ?

How to extract json array

$
0
0

Hy all,
I want to extract my json array for create a list of these object (JsonConvert.DeserializeObject<List>(objectJson);)
But i get an error :
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Citya.Models.Agence]' because the type requires a JSON array

How to extract my array off ?

Thx in advance

Dynamically loading Shell TabBar Tabs

$
0
0

Hi,

Attached VS2019 (Windows) Shell solution is loading TabBar Tabs dynamically. The issue is TabBar.Tab.Items.Clear() results in page not loading in iOS, and in Android only one of the 2 tabs has data.

What am I doing wrong?

See AppShellViewModel.cs

Thank you.

 class AppShellViewModel: BaseViewModel
 {
    private ObservableCollection<string> accounts = new ObservableCollection<string>();

    public AppShellViewModel()
    {
        Task.Factory.StartNew(RefreshAccountListAsync);
    }

    public ObservableCollection<string> Accounts
    {
        get => accounts;
        set => SetProperty(ref accounts, value);
    }

    private void RefreshAccountListAsync()
    {
        IsBusy = true;
        Accounts = new ObservableCollection<string>(new List<string>() { "Account1", "Account2" });

        Tab resultsTab = PickerTestApp.AppShell.Current.FindByName<Tab>("resultsTab");
        Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() =>
        {
            //On Android, clearing Items works.
            //On iOS, app does not load at all
            resultsTab.Items.Clear();

            //On Andoid: Account2 never loads ItemsPage
            //On iOS, app does not load at all
            foreach (var account in Accounts)
            {
                ShellContent resultsSC = new ShellContent();
                resultsSC.Title = account.ToUpperInvariant();
                resultsSC.Route = account;
                resultsSC.ContentTemplate = new DataTemplate(() => { return new PickerTestApp.Views.ItemsPage(); });
                resultsTab.Items.Add(resultsSC);
            }
        });

        IsBusy = false;
    }

}`

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).

iOS Binding Unity as a library

$
0
0

Hi all,

I don't even know where to start :D

Since alpha 2019.3 Unity offers the feature "Unity as a Library" https://blogs.unity3d.com/2019/06/17/add-features-powered-by-unity-to-native-mobile-apps/ which I'm currently trying to integrate into one of our Xamarin Apps.
There are descriptions how to do that natively for Android and iOS which I got both working fine.
Just for reference:
https://forum.unity.com/threads/integration-unity-as-a-library-in-native-ios-app.685219/
https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/
This is actually a really big deal so it is great working on it :D

However, I got it working fine for Xamarin Android. Now I'm trying on iOS which appears to be much more complicated.

The unity project will be exported as a native Objective-C++ framework (I think at least as there are .mm files using Objective C)
When using Sharpie to bind the framework I get a super large APIDefinitions file.
After some research I figured out that I have to define a scope to the Headers of the Framework, then the APIDefinitions are in fact much smaller and only reference the header files.

Now to my (current) problem:

If I open the ApiDefinitions then there is an interface UnityFramewok which comes from the UnityFramework.h file.
But this header holds a reference to a class UnityView which is not part of the headers. It is within the framework( at least it is within the Library project in Xcode so I assume it is bundled into the framework.)
I copied the .framework into the bindings Native References but I can't see any actual change happening when I do that.
The UnityView can not be found within the interface and I also can't import it from the library because the native reference is not available.

So how can I reference to a class of the framework from within an interface that is defined in the ApiDefinitions?

Thank you already!

Collection View not showing in master detail page

$
0
0

why is it that when l use the following code in my master detail page app.xaml.cs the collection view on the page does not show

 public App()
        {
            MainPage = new comicAppFinal.MainPage();
        }

but when the code below the collection view shows but l can not access the masterdetail page functionality anymore.

public App()
{
   MainPage = new Navigation(new MainPage())
}

How to get a parameter from MainActivity via DependencyService?

$
0
0

Hi!
I'm working with DependencyServie. Some method must implement in MainActivity and return a List result
How to get that List result from MainActivity via DependencyService?
Thank you!


Having trouble getting BackgroundFetch to work in Xamarin Forms iOS.

$
0
0

Hi,
I've been working on this for days now. I run our XF iOS app on a real device in debug mode. After it starts up, I press Home and the app goes to sleep - a debug statement in OnSleep tells me it got there. Next, I leave it alone and watch for the debug statement that tells me it got to PerformFetch. After 18 hours it still did not appear.
I know that iOS controls when it does a PerformFetch. But seriously, 18 hours and nothing?
Could iOS have messed up its timer or the minimum time for our app? Is there a way to reset it or does that happen when I reload a newly compiled version? Or do I have to change the actual version number?

For those that have read this far, you probably have some questions. Here are my settings and some snippets of my code.

In Info.plist, in Background Modes, I selected Enable Background Modes and Background Fetch.

On the device:
1) in Settings, I enabled BackgroundAppRefresh for the app.
2) In Settings, under the app, I enabled BackgroundAppRefresh

`
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{

UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
}

public override async void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
try
{
    var result = UIBackgroundFetchResult.NoData;
        bool bOK = await Util.RequestProjectsFromWebService(user);        
    result = UIBackgroundFetchResult.NewData;
        }
        catch (Exception ex)
        {
    result = UIBackgroundFetchResult.Failed;
        }
        finally
        {
               completionHandler(result);
        }

}
`
I'll be away for a few days, so it will be interesting to see how the app performs during that time.

Any ideas on how to get into PerformFetch would be much appreciated.
Regards,
Will

CarouselView implementation, CardsView nuget package

How to Authenticate an user using ADFS in xamarin forms?

$
0
0

Hi All,

I am new to xamarin forms. I need to authenticate the users using ADFS. Please guide me what are all prerequisite needed and how to achieve this ?

How can I set and get a selected value in my custom picker? The value is not changeable

$
0
0

How can I get the selected item of my custom picker? It always goes back to the initial state
I tried in several ways and I only had to question.

 public class MyDelegate : UIPickerViewDelegate
    {
        List<string> sourceList = new List<string>();
        public MyDelegate(List<string> list)
        {
            sourceList = list;
        }
        public override void Selected(UIPickerView pickerView, nint row, nint component)
        {
            UILabel label = new UILabel();
            label.Text = sourceList[(int)row];
        }

        public override UIView GetView(UIPickerView pickerView, nint row, nint component, UIView view)
        {

            try
            {

                UIView contentView = new UIView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, 80));

                UILabel label = new UILabel();
                label.Frame = contentView.Bounds;
                contentView.AddSubview(label);
                label.Text = sourceList[(int)row];
                label.Lines = 4;
                label.TextAlignment = UITextAlignment.Center;
                //Change the label style
                label.Font = UIFont.SystemFontOfSize(20);
                label.LineBreakMode = UILineBreakMode.TailTruncation;
                return contentView;

            }
            catch (Exception ex)
            {

                throw;
            }

            //return base.GetView(pickerView, row, component, view);
        }
        public override nfloat GetRowHeight(UIPickerView pickerView, nint component)
        {
            return 80;
        }
    }
}


   public class CustomPickerRenderer : PickerRenderer
    {
        List<string> itemList = new List<string>();
        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);
            var element = (CustomPicker)this.Element;
            Picker picker = Element;
            //itemList = picker.Items.ToList();       
                UITextField uITextField = new UITextField();
                uITextField = Control;
                UIPickerView uIPickerView = uITextField.InputView as UIPickerView;       

            if (this.Control != null && this.Element != null && !string.IsNullOrEmpty(element.Image))
            {
                var downarrow = UIImage.FromBundle(element.Image);
                Control.RightViewMode = UITextFieldViewMode.Always;
                this.Control.BorderStyle = UITextBorderStyle.None;
                Control.LeftView = new UIKit.UIView(new CGRect(0, 0, 5, 0));
                Control.LeftViewMode = UIKit.UITextFieldViewMode.Always;
                Control.BorderStyle = UITextBorderStyle.None;
                Control.RightView = new UIImageView(downarrow);
            }
        }
    }
}

Xam.Plugins.Notifier: Android Tap in Xamarin.Forms.Shell

$
0
0

Using Xam.Plugins.Notifier for Local Notifications I am able to show a notification in Android. However, when I tap the notification, it reloads the application. Similar to how a remote notification would.

I handle the OnNewIntent() in the MainActivitiy.cs but it never fires.

How do I tap a Local Notification made by Xam.Plugins.Notifier so that OnNewIntent() fires and I can show a Shell item?

    protected async override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        var title = intent.GetStringExtra("title");
        if (title != null)
        {
            await Shell.Current.GoToAsync("Tools/Sales");
        }
    }

How can i make a label fit/ auto size the grid row and column specified for it?

$
0
0

Hi,
I am using Grid layout to try making the app responsive and when i use label and set a font size to it, the label sometimes surpasses the space (grid.row & grid.colum) alocated for it.

Is it possible to make the label always fit the alocated space ?

<Grid RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="3.5*"/>
                <RowDefinition Height="6.5*"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" Grid.Column="0">
                <Image x:Name="imagemNav" Grid.Row="0" Grid.Column="0" Source="{local:ImageResource KiaiDay.Images.navigationImage.png}" Aspect="Fill"
                    HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
                <Grid Padding="20,10,20,0" ColumnSpacing="0" RowSpacing="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="3.5*"/>
                        <RowDefinition Height="4.5*"/>
                        <RowDefinition Height="2*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="6*"/>
                        <ColumnDefinition Width="4*"/>
                    </Grid.ColumnDefinitions>

...
                    <StackLayout Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Spacing="4">
                        <Label Text="Some text" FontSize="50" TextColor="White" FontFamily="{ StaticResource RegularFont}" Margin="20,0,0,0"/>
                        <Label Text="Some other text" FontSize="20" TextColor="White" FontFamily="{ StaticResource LightFont  }" Margin="25,-10,0,0"     
                                    Opacity="0.7"/>
                    </StackLayout>
...
</Grid>

How to change the name of app(In the screen, under the icon)

$
0
0

Hi guys,

I am building an app in Xamarin.Forms. I want to change the name of app, both iOS and Android. I tried to change the information in mainactivity.cs and Androidmanifest. However it is not working. I also don't know how to do it in iOS.

Would you please to help me?

Thank you very much.


Firing method in the View when a property in the ViewModel changes

$
0
0
Hi all,
As the title says I would like to call a method in my View when a property in my ViewModel changes. I was wondering if this is possible to do it by using the INotifyPropertyChanged interface or if I should implement the observer - observable pattern on my own for this particular task.

Practical example: I have a StackLayout in the View and an integer property called number in the ViewModel, I want to call a method in the View which makes sure there are exactly n (where n is the value of number) entries in the StackLayout every time number changes.

Note: number is the output of a calculation in the model and it doesn't have to appear anywhere in the view.

Thanks to everyone in advance.

How to set vertical align icon of the selected tab in a tabbedpage

$
0
0

Hi everyone, the icon of the selected tab aligns top vertically. How to set that alignment to center like others unselected tabs?

I am using FreshMVVM Framework and this is the code:

var masterDetailsMultiple = new MasterDetailPage();
masterDetailsMultiple.Title = "Master";
var menuPage = FreshPageModelResolver.ResolvePageModel();
masterDetailsMultiple.Master = menuPage;

var tabbedNavigation = new FreshTabbedNavigationContainer();
tabbedNavigation.On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
tabbedNavigation.AddTab("", "update2.png", null);
tabbedNavigation.AddTab("", "form2.png", null);
tabbedNavigation.AddTab("", "poll2.png", null);
tabbedNavigation.AddTab("", "star2.png", null);
tabbedNavigation.AddTab("", "ideas2.png", null);

Video is not played in iOS project

$
0
0

Hello,

I have used Plugin.MediaManager in my Xamarin.Forms application. It works perfectly in Android project, but in iOS project it does not.

I have added

VideoViewRenderer.Init();

in AppDelegate, and this is the code in the view:

        async void PlayStop_Clicked(object sender, System.EventArgs e)
        {
            if (this.BtnPlayStop.Text == "Start Video")
            {
                string video = Path.Combine(_videoPath, this.viewModel.Item.Video);

                if (File.Exists(video))
                {
                    await CrossMediaManager.Current.Play(video, MediaFileType.Video);

                    this.BtnPlayStop.Text = "Stop Video";
                }
            }
            else
            {
                await CrossMediaManager.Current.Stop();

                this.BtnPlayStop.Text = "Start Video";
            }
        }

Code enters the first if, since button changes its text to 'Stop Video' but no video appears. The video is a local mp4 file.

As I told, this works perfect in Android.

What's wrong?

Thanks

Jaime

audio controls on the lock screen

$
0
0

how do I show the audio controls on the lock screen and when I press the power button on ios and android, this in Xamarin Forms.

How to make a stacklayout fixed to the bottom of the screen in a scrollview

$
0
0

l have code that has views in a scrolleview.. l want to be able to make the last stacklayout to be fixed in the scrollview such that all other elements can scroll but the stacklayout is fixed. Much like fixed footer in a web page

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

<NavigationPage.TitleView >



</NavigationPage.TitleView>  






<CollectionView.ItemsLayout>


Horizontal


</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>


<Grid.RowDefinitions >


</Grid.RowDefinitions>
<Grid.ColumnDefinitions>

</Grid.ColumnDefinitions>

     </StackLayout>   



Any Ideas..

Viewing all 91519 articles
Browse latest View live


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