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

Absolute Layout Sizing

$
0
0

Using Absolute Layouts allows for positioning objects onto a definite spot within that layout. It does this based off of coordinates within the layout. You put in those coordinates, the object sets itself within them. However, my problem lies in the fact that for the iPhone 5s on down, the width of the screen is much smaller than the iPhone 6 on up, thus throwing off the positioning of the absolute layout.

In my exact scenario, I'm using a Stack Layout that contains many items, one of which is an Absolute Layout that contains a couple of items for itself. I've set up the coordinates so that the two objects within the Absolute Layout are stacked on top of each other, and then the rest of the Stack Layout items are underneath. However, I'm always left with a large gap between the Absolute Layout and the rest of the items. I tried giving the Absolute Layout a defined height proportional to the size of the screen, and that worked, but only for the screen size I'd sized it to. Change screen sized (switching from iPhone 6 to iPhone 5) and now things are out of whack again since the screen sizes are different.

So in the end, my question is this: Is there a way to set an Absolute Layout to only take up as much room as needed and use actual positioning properties instead of placing objects with coordinates? (e.g., "top left" instead of "0, 0") Thank you in advance!

(BTW, below I have two rough sketches: the first is what I'm aiming for and the second is what I getting.)


Why calculating text in skiasharp and gdi return not equal result

$
0
0

FamilyName Arial FontSize 12 FontStyle Regular
layout = _gg.MeasureString("A", font, layout, strFormat);
return new SizeF(layout.Width, layout.Height);
Width=16.32552
Height=19.8749962

SKPaint paint=new SKPaint();
paint.Typeface = m_typeface;
float dpi=96;
float punct=72;
paint.TextSize = (int)Math.Ceiling(m_emSize * ( dpi/ punct));
paint.MeasureText("A", ref bounds);
m_actualWidth = Math.Max(m_actualWidth, bounds.Width);
m_actualHeight += m_lineSpacing;
m_actualWidth=19
m_actualHeight=13

Binding to a Command and Type Safety

$
0
0

Perhaps this is simply an uneducated question I am not sure. I use a number of Command Bindings similar to what is described here:
https://blog.xamarin.com/simplifying-events-with-commanding/

I like this approach quite a bit because it allows me to include virtually all code behind in the View Model. However, I am finding a few drawbacks that can sometimes cause problems.

1) When I bind a control in XAML the command (in this case "SquareRootCommand") does not refactor in Visual Studio with the attached view model. This causes problems when the command name gets renamed in the view model, leaving behind an orphaned control that no longer fires its intended command. Unfortunately, there are no compiler errors as I would have hoped. In fact it appears there not really any errors at run time either, Xamarin simply ignores the command.

2) Sometimes I forget to the declare the ICommand property in the view model as public. This again orphans the control because it can not reach the non public property. Again there are no compiler errors.
//Note the command is not public
ICommand SquareRootCommand { get; private set; }

Is this the intended behavior for Visual Studio or are there any plans to make the bound property/command in the XAML trigger a compiler error, similar to how an error is triggered if a XAML control EVENT is not properly found/wired up in the page code behind?

I understand the complexity that may exist since the design of the view model is not necessarily going to be defined the same way each time (it is not after all the code behind page file). However, is there an interface I should implement or a design practice that I should incorporate that may allow for more type safety in this regard?

How to enable Android designer in Visual Studio?

$
0
0

My Android designer in Visual Studio is not showing anything at all. Anyone knows how to fight this?
Screenshot attached

image

Error: This version of Xamarin.Mac requires the macOS 10.14 sdk

$
0
0

Hello,

I have this error when trying to compile my project on Xamarin.Mac.
I have the latest OS version and the latest XCode.

Error MM0091: This version of Xamarin.Mac requires the macOS 10.14 SDK (shipped with Xcode 10.1). Either upgrade Xcode to get the required header files or use the dynamic registrar or set the managed linker behaviour to Link Platform or Link Framework SDKs Only (to try to avoid the new APIs). (MM0091)

I had it after unifying my project to the new API.
Apparently this is required to compile my project into 64bits.
So I know that in the error it is written: "to try to avoid the new APIs", but then how do I compile my project into 64bits?

Pre-API-unifying, I have marked all my projects to compile into 64bits and lost the 32bits warning at the compilation, but the MacOS still sees it as nonfit for a 64bits OS.

Maybe I am missing something in the 64bits compilation? Why, even though I compile it to 64b, the OS does not see it?

EDIT: forget that I can remove the 32b warning. I succeeded in removing it from the old dev environment, with an old mono and an old ide and an old OS. But in this new env even though I specify 64bit in all my projects it just does not want to compile in 64 bits...

UWA doesn't run

$
0
0

DEP3321: To deploy this application, your deployment target should be running Windows Universal Runtime version 10.0.15063.0 or higher. You currently are running version 10.0.10240.17443. Please update your OS, or change your deployment target to a device with the appropriate version.

RichTextView with NSTextView problem

$
0
0

Hi,

I need to use a Rich NSTextView to view an RTF file.

I can correctly display the RTF file and I have the bar to change font, size, fat, etc ...

Only, I do not know why, when I want to change the size of the font or the color of the text, it does not work. The rest is working properly.

Can someone help me and tell me why?

Thank you

Adding value from a popup page to ContentPage

$
0
0

Hi all,
My setup is like this:
1- I have a content page with a listview of items that each has a Score.
2- By tapping an item in the list it opens up a popup page with another listview of values.

I can easily pass SelectedItem.Id from the ContentPage to the Popup page. However, I do not know how to add the value from the Popup page listview to the Score in the ContentPage and update it.

Any help will be much appreciated.

This is my code in the PopupViewModel:

    async void AddValue(int selectedValueID)
    {
        bool isUserAccept = await Application.Current.MainPage.DisplayAlert
            ("ValuePoints", "Would you like to add these points?", "OK", "Cancel");

        if (isUserAccept)
        {
            _student.Score += _points.Mvalue;

            //_studentRepository.UpdateScore(_student.Score);  //Tried that but didn't work

            _studentRepository.UpdateStudent(_student);

            await Application.Current.MainPage.DisplayAlert
            ("Value Points", "Value points were added.", "OK", "Cancel");

            await PopupNavigation.Instance.PopAsync();
        }
    }

    MValue _selectedValueItem;
    public MValue SelectedValueItem
    {
        get => _selectedValueItem;
        set
        {
            if (value != null)
            {
                _selectedValueItem = value;
                NotifyPropertyChanged("SelectedValueItem");
                AddValue(value.MvalueID);
            }
        }
    }

CS0103 The name 'Resource' does not exist

$
0
0

In new version of xamarin with vs 2015 i get this message in every time i use resource.id

Should an app support devices that has animation disabled?

$
0
0

Is it the developer's responsibility to always code in that essence that although the user has animation disabled, the app should work properly?

And/or should the developer check programatically if the user has disabled animation and alert the user?

I just finished debugging a problem that's been bugging me for 3 days. A couple of user reported that the buttons that they are tapping on are not working. In the end it turned out to be a setting that they disabled under Developer Options on their devices:

  • Window animation scale
  • Transition animation scale
  • Animator duration scale

What do you think?

Command CanExecute bug?

$
0
0

Is it just me, or does binding a command with the optional CanExecute property not work?
Xamarin Forms 3.5.0.129452 - Current on 07feb2019

In this case the button never enables.

                <Button
                    Command="{Binding CopyFilesCommand}"
                    Text="Copy" />
        private ICommand _CopyFilesCommand;
        public ICommand CopyFilesCommand
        {
            get { return _CopyFilesCommand ?? (_CopyFilesCommand = new Command(On_CopyFilesCommand, (x) => CanCopyFiles)); }
        }

        public bool CanCopyFiles
        {
            get
            {
               //Logic to determine true or false
            }
        }

Property being used as the deciding factor is calling both OnPropertyChanged as well as Command.ChangeCanExecute
So a SelectedPath property changes - it yells out that the command should be re-evaluted for 'can' or 'cannot'
                OnPropertyChanged(nameof(CanCopyFiles));
                ((Command)CopyFilesCommand).ChangeCanExecute();

In this case the button never enables.

However if I add one simple line to the XAML and manually bind the IsEnabled to the exact same property - THEN the button enables and disables as expected - proving that all the other code is right.

                <Button
                    Command="{Binding CopyFilesCommand}"
                    IsEnabled="{Binding CanCopyFiles}"
                    Text="Copy" />

Its an easy work around... But the point is that just binding to the command should be enough, provided the command is created knowing what property controls its can factor. Right?

Error: Attribute has already been defined (APT0000)

$
0
0

At work, I switched branches and now I can't build any branch due to:

error: Attribute "text" has already been defined (APT0000) Resources/values/attrs.xml
error: Attribute "closeIcon" has already been defined (APT0000) Resources/values/attrs.xml
error: Attribute "text" has already been defined (APT0000) Resources/values/attrs.xml

The other seven developers don't have this issue.

I've done the following:

  1. Deleted obj/Debug folder to clear out resource cache files and rebuilt
  2. Removed all packages and deleted them and rebuilt
  3. Deleted Visual Studio Community for Mac and reinstalled
  4. Deleted the repository and cloned it again and rebuilt

Anyone else have something to try? I've run out of ideas.

how to store login credentials in xamarin forms, as we do store in shared preference?

$
0
0

How can I store login credentials in xamarin forms, in xamarin android i was able to use shared preference but here if I use it would not work for Iphone?

Kindly help me with this, I am totally new to xamarin.

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.

How to link ActivityIndicator to Image loading using xaml?

$
0
0

I can't seem to get activityIndicator to link its visibility and running properties to a desired image loading (from url).
Can someone please post a xaml example how this is done?

Thank you!


How to subscribe an event without setting Control.Delegate to null in a Xamarin.iOS custom renderer

$
0
0

I need to extend the Xamarin.Forms ListView to have an async method for scroll the list view to top. Create a control and the custom renderer to subscribe the scrolling ended event inside the OnElementchanged override.

Major code:
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
...
//Without settings Delegate to null, I am getting "Event registration is overwriting existing delegate..." error

Control.Delegate = null;

//Below line is actually override the Delegate, and cause some problems (for example the Grouping for the list view is not working )
Control.ScrollAnimationEnded += OnScrolledToTop;
...

}

My questions is how should I do in the custom renderer without setting Control.Delegate to null in this Xamarin.iOS custom renderer?

Many thanks.
Kevin Hu

Images not showing in XF OSX project

$
0
0

The following is an extract from the XAML or a view whichworks successfully on UWP, Android and iOs platforms:


<Image x:Name="Logo" Style="{StaticResource LogoStyle}">
    <Image.Source>
       <OnPlatform x:TypeArguments="ImageSource">
        <On Platform="Android" Value="logo_splash" />
        <On Platform="UWP" Value="Assets/logo_splash.png" />
        <On Platform="macOS" Value="logo_splash"/>
       </OnPlatform>
    </Image.Source>
    <Image.HeightRequest>
        <OnIdiom x:TypeArguments="x:Double" Desktop="100" Phone="95"/>
    </Image.HeightRequest>
    <Image.VerticalOptions>
        <OnIdiom x:TypeArguments="LayoutOptions" Desktop="End" Phone="Start"/>
    </Image.VerticalOptions>
</Image>

As you can see I've added an On Platform selector for the macOS platform.

While the image appears as expected on other platforms it is not seen on the Mac.

In my OSX project I've added the image to the resources folder and set the build action to 'BundleResource'.

I'm using package Xamarin.Forms 2.5.0.122203.

I can't help thinking I've missed something obvious, can anyone please suggest what I'm doing wrong.

Thanks in advance
Dave

XF - Android - SMS and Call Log Permissions violation. (Not in manifest)

$
0
0

I have an app built in Xamarin.Forms and I'm in the middle of publishing to the stores,

iOS version is already approved.
Android, ** approved **then **removed ** by:

Violation of the Permissions policy
SMS and Call Log Permissions are subject to additional restrictions.....

and they have these options:
Option 1) If your app does not require access to Call Log or SMS permissions:
Option 2) If your app’s use case is not eligible but you require additional time to make the necessary changes to your app
Option 3) If your app is a default handler, or you believe your app qualifies for an exception

the weird thing here is, I don't request any of those permissions at all, my app neither send/receive sms, or read/write call logs or perform calls and I don't have anything regarding these permissions in my Manifest nor the merged Manifest

what I do have in my Android Manifest is the following:

        <permission android:name="com.myapp.xamarin.permission.C2D_MESSAGE" android:protectionLevel="signature" />
            <uses-permission android:name="android.permission.USE_FINGERPRINT" />
            <uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
            <uses-permission android:name="android.permission.WAKE_LOCK" />
                <uses-permission android:name="com.myapp.xamarin.permission.C2D_MESSAGE" />
            <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="remove" />
            <application android:label="My App Name" android:icon="@drawable/icon">
                <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
                <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
                    <intent-filter>
                        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                        <category android:name="com.myapp.xamarin" />
                    </intent-filter>
                </receiver>
                <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/icon_pn" />
            </application>

so, yes, I'm using Xamarin.Firebase to perform push notifications in my app, so, I don't know if internally is requesting those permissions or something,
or how the 'GET_ACCOUNTS' permissions is added after the manifest merge,

I already tried, removing manually all those permissions from the manifest, following this: https://support.hockeyapp.net/kb/client-integration-android/hockeyapp-for-android-sdk#4-7-1-removing-external-storage-permission

which basically is adding this in the manifest:
<uses-permission android:name="android.permission.READ_SMS" tools:node="remove" />

does anyone have any idea on how to approach this issue, I've also been looking into the documentation of all 3rd party libraries that I have, to see if there's something regarding these permissions but no luck so far,

any idea, comment will be much appreciated,

thanks folks!

iPhone X and safe margins with Xamarin Forms

$
0
0

Hi!

I have finished my app, but I have tested it with the iPhone X simulator and I'm totally out of the safe margins.

I'm searching for info everywhere, but I can't find anything specific to that.

I have alleviated the problem using always a NavigationBar, but the problem still persists if I put the device in landscape mode.

Does someone know how to apply extra margins if necessary with the iPhone X?

Thanks!

Detect specific device

$
0
0

Is there any way to detect a specific device (type)? More exactly I want to know if a user uses a iPhone X (or a iOS device with no physical Home Button). That's because I have to apply some specific margins/paddings for these devices and it just look ugly on other devices. Because the "virtual home bar" at the bottom is overlaying some content (yes, I know that this device is not released yet, but I have to fix it for a few Apps so I start early). And of corse for the site if the device is in landscape. Therefore I also need to differ between Top -> Left and Top -> Right Landscape modes. Also I need to differ in C# as well in XAML.

Viewing all 204402 articles
Browse latest View live


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