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

How to resolve AndroidZipAlign error?

$
0
0

After upgrading Visual Studio to 15.6, my Android build fails with the following error. Does anybody know how I can resolve this?
The problem is occurring no matter which device I am deploying to, so the arm64 that appears below is just one example - the others do it too.

AndroidZipAlign Task
Alignment: 4
Source: G:\tfs\MyApp\Top\MyApp.Android\obj\Debug\android\bin\com.MyApp.MyApp-arm64-v8a.apk
DestinationDirectory: bin\Debug\
C:\ProgramFiles\Android\AndroidSDK\build-tools\25.0.2\zipalign.exe 4 "G:\tfs\MyApp\Top\MyApp.Android\obj\Debug\android\bin\com.MyApp.MyApp-arm64-v8a.apk" "bin\Debug\com.MyApp.MyApp-arm64-v8a-Signed.apk"
Output file 'bin\Debug\com.MyApp.MyApp-arm64-v8a-Signed.apk' exists
"zipalign.exe" exited with code 1.
Done executing task "AndroidZipAlign" -- FAILED.


[PRISM] IEventAggregator with a contentView

$
0
0

Hi,

I got a problem using Prism and IEventAggregator.

I have a Content Page register in my app :

containerRegistry.RegisterForNavigation<FicheSMUR>();

In my FicheSMURViewModel, I have an IEventAggregator : (partial code)

private IEventAggregator _ea;
public FicheSMURViewModel(IEventAggregator ea) 
    {
        _ea = ea;
}

So far, so good. But in this same ContentPage, I have a ContentView bind. I want to publish an event from my ContentPage and receive it in my contentView. So I do like follow : (partial code)

private IEventAggregator _ea;

private ContentView _pageContent;
    public ContentView PageContent
    {
        get { return _pageContent; }
        set { SetProperty(ref _pageContent, value); }
    }

public FicheSMURViewModel(IEventAggregator ea) 
    {
        _ea = ea;
    PageContent = new PatientTab();
}

public void OnNavigatingTo(NavigationParameters parameters)
    {
        _ea.GetEvent<FicheChangedEvent>().Publish((string)parameters["ficheName"]);
    }

And in my PatientTabViewModel : (partial code)

public PatientTabViewModel(IEventAggregator ea) 
    {
        ea.GetEvent<FicheChangedEvent>().Subscribe(FicheChanged);
}

private void FicheChanged(string Title)
    {
        //TODO: 
    }

But then I crash on execution, seems like Unity can't find IEventAggregator in PatientTab.
Am I doing something wrong ?

Thanks

Embedding Xamarin.Forms elements into custom view renderer

$
0
0

Hi, all. I want to create custom renderer with native layout and import multiple Xamarin.Forms pages.
Basically I want to use something like CreateFragment from here link
but in custom renderer. Is it possible?

image

Instances of ViewModels and Changing Properties from other classes?

$
0
0

I have a button with a command , it's BindingContext is set to RedViewModel

    <ContentView.BindingContext>
        <vm:RedViewModel />
      </ContentView.BindingContext>

    <Button x:Name="BlueButton"
                Grid.Row="0"
                Command="{Binding NavigateToBlueVCommand}"
                Text="Blue" />

This is bound to a command property in the RedViewModel;

    public ICommand NavigateToBlueVCommand { private set; get; }

    public RedViewModel() 
            {
                NavigateToBlueVCommand = new Command(execute: () =>
                {
                    NavigationClass.ChangeView(new BlueView());

                });
        }

The NavigationClass takes the passed view and adds it to a stack and sets the MainPageViewModel's property to the new Vaule (The setter calls the OnPropertyChanged() method )

    private static List<ContentView> _navigationStack = new List<ContentView>();
    private static MainPageViewModel _mpvm = new MainPageViewModel();


            public static void ChangeView(ContentView nuView)
            {
                if (nuView == null) throw new NullReferenceException();
                try
                {
                    _navigationStack.Add(nuView);
                    _mpvm.DisplayedView = nuView;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

            }

I have debugged it and can follow all the setps through and the value of displayedview property on _mpvm exactly matches blueView and the OnPropertyChanged(), identifies the correct property that called it, but the UI does not change.

if however I change the command execute code in the ViewModel, so the value is assigned in the ViewModel it works fine;

        NavigateToBlueVCommand = new Command(execute: () =>
        {
          DisplayedView = new BlueView()  ;
        });

Therefore, my theory is, the problem is in the fact that I create a new instance of the MainPageViewModel, in the Navigation Class, instead of using the instance created when the Mainpage BindingContext was assigned ? (or more likely this is just crazy, way of the mark thinking).

The attachable property Phone was not found in type OnIdiom

$
0
0

I started getting this XAML warning after the latest XF version on VS 2017 v15.7.1.
This is the code in App.xaml:

<OnIdiom x:Key="largeFontSize"  x:TypeArguments="x:Double">
    <OnIdiom.Phone>
        <OnPlatform x:TypeArguments="x:Double" iOS="23" Android="23"  />
    </OnIdiom.Phone>
    <OnIdiom.Tablet>
        <OnPlatform x:TypeArguments="x:Double" iOS="28" Android="28"  />
    </OnIdiom.Tablet>
</OnIdiom>

The attachable property Phone was not found in type OnIdiom.

And I also get another warning here:

<Thickness x:Key="pageContentPadding">10,0,10,0</Thickness>

The type 'Thickness' does not support direct content.

I've used these styles since the beginning of the app with no warning, until now.
How should I change them now?

Using declarative style C# instead of XAML - should Xamarin redirect XAML efforts elsewhere?

$
0
0

Introduction

Miguel tweeted:
"I should have never added Xaml and instead invented our own ...", expressing regrets about having to deal with XAML (standardization) problems.

My response was:
"I would applaud dropping XAML altogether. Advancements in C# (declarative syntax) have eliminated any advantages of a separate markup language for years. Why would you want to hand-code an object serialization format? Why waste time on duplicating dev tools for features that c# already offers?"

David expressed an interest to see how I have been creating Xamarin Forms markup in declarative style C#, instead of in XAML, for the past few years. So I write this post to provide a concrete example, and share the reasoning behind my remark (which was deliberately lacking nuance - it is Twitter after all).

Redirecting Xamarin IDE team effort

Why do I spend time on this? In the past years I only experienced advantages from using declarative C# instead of XAML. Given that the core challenge for the Xamarin IDE teams remains to improve the developer productivity, I would love to see some of the effort now being spent on (imo redundant) XAML tooling to be redirected towards reducing IDE bugs and speeding up the dev cycle, i.e. Live Player.

I recently investigated Google's Flutter (build beautiful native apps in record time), which by design has no separate language for markup and which offers hot reload - which is like a Xamarin Live Player without any limitations and a refresh time of 400-600 ms (I checked on devices and emulators). This is what I want from Xamarin!

This is the competition Xamarin is facing today. Some developers are already switching from Xamarin to Flutter because of developer tooling productivity, which apparently can be more important than language or framework or experience. As a Xamarin veteran, I get why they do this. I feel that unless there is a significant team increase, Xamarin needs to focus and redirect existing effort towards developer productivity, meaning less IDE bugs and faster development cycle.

Example
.
Here is an unabridged example of a simple registration code page in a production app I wrote:

Content = new Grid { 
    RowSpacing = 0, 
    RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition {}},
    Children = {
        PageHeader.Create(PageMarginSize, nameof(vm.RegistrationTitle), returnToPreviousViewCommandPropertyName: nameof(vm.CancelEnterRegistrationCodeCommand), centerTitle:true),

        new ScrollView { Content = new Grid {
            RowDefinitions = {
                new RowDefinition { Height = 170 },

                new RowDefinition { Height = 75 },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto }
            },
            RowSpacing = 0,

            ColumnDefinitions = {
                new ColumnDefinition { Width = 160 },
                new ColumnDefinition { }
            },

            Children = {
                new Label {
                    Margin = fieldNameMargin, LineBreakMode = LineBreakMode.WordWrap, 
                    HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Center, 
                }.SetFontSize(WspFontSizes.Size15)
                 .SetColRow(0, 2, 0, 1)
                 .Bind(nameof(vm.RegistrationPrompt)),

                new Label { Text = "Registration code", VerticalOptions = LayoutOptions.End, Margin = fieldNameMargin }.SetFontSize(WspFontSizes.Size13)
                .SetColRow(0, 1, 1, 2),
                new Label { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.End, Margin = fieldNameMargin }.SetFontSize(WspFontSizes.Size13)
                .SetColRow(1, 2, 1, 2)
                .Bind(nameof(vm.RegistrationCodeValidationMessage)),

                new Entry {
                    Placeholder = "E.g. 123456", HeightRequest = 44, Keyboard = Keyboard.Numeric, 
                    BackgroundColor = WspColors.White.ToColor(), TextColor = WspColors.Gray1.ToColor(), Margin = fieldMargin }.SetFontSize(WspFontSizes.Size15)
                .Bind(nameof(vm.RegistrationCode), BindingMode.TwoWay)
                .Id(AId.RegistrationCodePage_CodeEntry)
                .SetColRow(0, 2, 2, 3),

                new Button {
                    Text = "Verify",
                    Margin = PageMarginSize,
                    HeightRequest = 44,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    TextColor = WspColors.White.ToColor(),
                    BackgroundColor = WspColors.ColorValueAccent.ToColor()
                }.SetFontSize(WspFontSizes.Size13)
                 .Id(AId.RegistrationCodePage_VerifyCodeButton)
                 .Bind(Button.IsVisibleProperty, nameof(vm.CanVerifyRegistrationCode))
                 .Bind(nameof(vm.VerifyRegistrationCodeCommand))
                 .SetColRow(0, 2, 3, 4),
            }
        }}.SetColRow(0, 1)
     }
 };

Nothing advanced is going on here, I use standard C# language features to reuse controls (e.g. PageHeader.Create method ) and to simplify data binding (.Bind extension methods). In my eyes the above reads similar to equivalent XAML.

Which is not very surprising given that XAML is at its heart just an object serialization format in XML. In other words, XAML does what the new keyword in C# does.

Now, C# is designed for humans; while XML is better for tools such as visual designers. As a matter of fact, that was the vision for (WPF) XAML: that human designers could use a tool (Blend) to create a UI that developers could consume. However, I experienced how that vision, even in the best possible time and scenario, failed to deliver (I Built a WPF app for Windows tablet together with a XAML book authoring, leading designer, who was a master in Blend, when that was THE tool. The UI was beautiful and totally unmaintainable). So even if there would come an ultimate visual designer tool for Xamarin Forms, equivalent to the best that Blend ever was, it would still fail for the same reasons. Time to move on, like Flutter?

So, anyone (Xamarin devs and Xamarin team) wants to chime in on either XAML versus C# or redirecting Xamarin IDE efforts?
I'm really curious how Xamarin devs (especially experienced ones) see this.

Thanks!

UWP : FillAndExpand expand out of screen of a modal content page

$
0
0

In a modal content page, I have a grid :

<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="40" /> <RowDefinition Height="40" /> </Grid.RowDefinitions> <StackLayout Spacing="0" VerticalOptions="Start" HorizontalOptions="FillAndExpand" Orientation="Vertical"> <2 LABELS /> </StackLayout> <Button Grid.Row="1" /> <Button x:Name="BadButton" Grid.Row="2" /> </Grid>

The Button called BadButton is pushing out of the screen or is barely visible at the bottom of the screen.
When I checked the size of the MainPage, it says 616px. The Grid size is 640px !

What I am doing wrong ? Is it a bug of Xamarin Forms ?

Datepicker, serious problems

$
0
0

Hi all together,
i have serious Problems with Datepicker.

ProjectWorkTimeDetailViewModel.cs
public class ProjectWorkTimeDetailViewModel
{
more code..................
public override void OnNavigatedTo(NavigationParameters parameters)
{
base.OnNavigatedTo(parameters);
if (parameters.ContainsKey("PWT"))
{
var projectWorkTime = (ProjectWorkTime)parameters["PWT"];
CurrentWorkTime = new ProjectWorkTimeEdit(projectWorkTime);
CurrentWorkTime.PropertyChanged += OnPropertyChange;
}
}

private void OnPropertyChange(object sender, PropertyChangedEventArgs e)
    {
        if (!Title.EndsWith("*"))
        {
            Title = Title + " *";
        }
        _canSave = true;
        SaveCommand.RaiseCanExecuteChanged();
    }

}

ProjectWorkTimeDetail.xaml

                <ViewCell>
                    <StackLayout Orientation="Horizontal"   Padding="13,0">
                        <Label Text="Arbeitstag:  " VerticalOptions="Center"></Label>

                        <DatePicker Format="dd MMM yyyy"
                                Date="{Binding CurrentWorkTime.WorkDay,Mode=TwoWay}"
                                HorizontalOptions="FillAndExpand"></DatePicker>
                    </StackLayout>
                </ViewCell>

ProjectWorkTimeEdit.cs
public class ProjectWorkTimeEdit : BindableBase
{
ProjectWorkTime _entity;

    public ProjectWorkTimeEdit (ProjectWorkTime entity)
    {
        if (entity == null)
        {
            throw new ArgumentNullException(nameof(entity));
        }

        _entity = entity;
       _workDay = entity.WorkDay;
        _job = _entity.Job;
        _workTime = _entity.WorkTime;
    }

    DateTime _workDay;
    public DateTime WorkDay
    {
        get => _workDay;
        set => SetProperty(ref _workDay,value);
    }

........... more code
}

As you can see i'm initializing 'ProjectWorkTimeEdit.cs' and set values in the Constructor. After that, i add the 'OnPropertyChanged' EventHandler.

Directly after this Line:
CurrentWorkTime.PropertyChanged += OnPropertyChange;

I have a Event fired from

 public DateTime WorkDay
{
     set => SetProperty(ref _workDay,value);
}

here without doing anything

I'm shure that this problem has something todo with the Datepicker because if i commented out the Datepicker all works as expected.

Any idea???

Thanks in advance
Peter


The call is ambiguous between the following methods or properties...

$
0
0

Hello,

I have started a new Xamarin.Forms project and after upgraded Xamarin.Forms package (3.0.0.446417), I got this warning on InitializeComponent method call in App.xaml.cs (The call is ambiguous between the following methods or properties: 'App.InitializeComponent()' and 'App.InitializeComponent()') or in pages ((The call is ambiguous between the following methods or properties: 'MyPage.InitializeComponent()' and 'MyPage.InitializeComponent()')).
This warning doesn't appear for next pages I have newly created.
Any idea?

Thanks.

The variable Session exists in Xamarin? As in the .NET Framework?

$
0
0

Good afternoon,

I am looking for a way to use a Session variable like the one I used in the .NET Framework but now I want to use it in Xamarin in an application.

Specifically to have at hand the logged in user and some more variables that can be a list.

I had planned to make a class called session and have that data and send it to ALL pages in each page pass but I do not know if there is something in Xamarin already prepared to use it.

Thank you, I await your recommendation.
Much success.

Xamarin project not running, netstandard2.0 error

$
0
0

Im learning Xamarin, when I try to create a project and build it, it gives me this error:

The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly , C:\Users\XXXX.nuget\packages\xamarin.forms\3.0.0.482510\build\netstandard2.0\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral

I really dont know how to solve it. I also tried: docs.microsoft.com/en-us/xamarin/xamarin-forms/internals/net-standard

Did Xamarin announce a media player for Xamarin Forms?

$
0
0

I am sorry for the general nature of this question, but my memory (or lack of) is driving me nuts with this.

I seem to remember, maybe a month or two ago, that Xamarin announced a media player for use within Xamarin Forms. I remember it making bold claims about handling the platform-specifics of being able to continue streaming even when the app was in the background. I didn't have time to investigate at the time, so I just thought, "I'll come back to that later." Now I can't find a thing about it.

Does anyone recognise this or did I dream the whole thing?

~ Patrick

How to play mp3 player using xamarin.forms?

$
0
0

Hi ,
I am using MediaManager Plugin for playing mp3.and its works fine when i play individually using the below coding

await CrossMediaManager.Current.Play("http://amendinfotechnologies.com/songs/04%20Bat%20Out%20Of%20Hell.mp3");

But my problem is , to play a sequence of media items,need to add it into queue.here i failed to add it.
please any one can direct me in right way.

How to play MP3 audio in xamarin.forms from a remote online url?

$
0
0

Hi,
I am trying to play an audio MP3 file in XForms App by using a server url where this MP3 file is hosted for example: www.xyz.com/example.mp3
I am using Plugin.MediaPlayer. It plays mp3 from app resources but do not know how to play from a live url. Kindly suggest some solutions.
Thanks

Xamarin.Android.Common.targets - Name cannot begin with the '$' character, hexadecimal value

$
0
0

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(3,3): Warning: Name cannot begin with the '$' character, hexadecimal value 0x24.

I am building a Xamarin Forms application and I have been trying to resolve the issue. I just can't find online resources to get me through this. Is there anyone who knows whats causing this. There is no name that starts with '$'.


Setting a TimePicker to 24-hour format

$
0
0

I've searched the internet and so far there is no solution that is working. I'm trying to SHOW the time in 24 hour format. When the user selects the control, it currently presents iOS in 24 hour format, Android is still the clock where you must select AM/PM. That is fine. After the user selects the time, it always shows in AM/Pm

Here's what I've tried:

Xamarin - currently there is nothing available for cross-platform

iOS -

var timer = (UIDatePicker)Control.InputView;
timer.Locale = new Foundation.NSLocale("no_nb");

Android -

protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
      {
            base.OnElementChanged(e);
          Control.TextLocale = new Java.Util.Locale("es");
      }

I have one found one thing that works for Android, however it requires I manually set Control.Text to the "HH:mm" format, which ended up being unreliable (would only work on 2 of 3 TimePickers).

Is there any consistent solution for showing 24-hour format for a TimePicker?

How to Create Nuget packages for Xamarin forms ( custom views / services)??

$
0
0

Hi all can someone please shed some light on creating Nuget packages for xamarin.forms

I'm currently looking into trying to make some Custom view controls / services's for Xamarin.Forms, has any one got helpful tips like from which starting project to setup and adding the proper config files such as the nuspec file in some step by step fashion.

I did use James Montemagno plugin https://marketplace.visualstudio.com/items?itemName=vs-publisher-473885.PluginForXamarinTemplates which i was able to generate the nuget package file but could install the nuget package in my project with an error

Could not install package ''. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework.

So james plugin is also kinda old with no VS 2017 support and Xamarin moves so fast these days is this the preferred method developers follow?? I really wanna starting contributing some open source projects but where do i start.

Also whats up with NuGetizer 3000 can i use this? https://github.com/NuGet/Home/wiki/NuGetizer-3000 - The goal of the NuGetizer 3000 project is to make it as easy as possible to create and publish a NuGet package, including bait-and-switch packages, and provide guidance to users along the way.

I'm using a window 10 machine with VS 2017 but also setup VS 2015 for Jame's plugin

How to open an app xamarin forms via intent from other app (native of xamarin forms) ?

$
0
0

I had developed a xamarin forms app and i want to wake up from another app, I already try with intent using the package name but not work, it´s possible to do this or maybe a solution?

FlexLayout not working

$
0
0

Im trying to use FlexLayout but it keeps giving me this error:

(1,1): error: Position 8:14. Type FlexLayout not found in xmlns http://xamarin.com/schemas/2014/forms

Xam Forms Layout issue

$
0
0

I am attempting to create a very simple page and running into an issue. The projectis xamarin forms. I want the page to dispaly different sections. Each section will have a header. The header must have a background color that stretches from one side to another with no margin or padding. I then want the text inside the header to have a margin so it is not pushed up against the side of the page. I have tried stack panels and grids to no avail. Can anyone show me what I am doing wrong.


Heading 1

content


Heading 2

content


Heading 3

content

Here is my xaml


<Grid.RowDefinitions>




</Grid.RowDefinitions>

                <StackLayout Grid.Row="0" Spacing="0" Padding="0">

                    <StackLayout Spacing="4" Padding="0,0,0,15">
                        <Label Text="Description" HorizontalTextAlignment="Start" BackgroundColor="Silver"  LineBreakMode="NoWrap"/>


                        <Label Text="Details" FontSize="12">
                        </Label>
                    </StackLayout>
                    <StackLayout Spacing="4" Padding="0,0,0,15">
                        <Label Text="Address"  HorizontalTextAlignment="Start" BackgroundColor="Silver" LineBreakMode="NoWrap">
                        </Label>
                        <Label Text="Address Details" FontSize="12">
                        </Label>
                    </StackLayout>

......

Viewing all 91519 articles
Browse latest View live


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