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

Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException

$
0
0

Facing Below issue.Please help me to resolve it

Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).

Native stack trace:

0   CoreFoundation                      0x0000000102e4612b __exceptionPreprocess + 171

1   libobjc.A.dylib                     0x0000000110717f41 objc_exception_throw + 48

2   CoreFoundation                      0x0000000102e4b2f2 +[NSException raise:format:arguments:] + 98

3   Foundation                          0x0000000103a75d69 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193

4   UIKit                               0x00000001074dc209 -[UITableView _endCellAnimationsWithContext:] + 19416

5   UIKit                               0x00000001074f7075 -[UITableView endUpdates] + 75

6   AutoCompleteExample.iOS             0x00000001027679f9 xamarin_dyn_objc_msgSend + 217

7   ???                                 0x0000000130a75362 0x0 + 5111239522

Trigger a Picker programmatically

$
0
0

Hi there,

I have a picker as a children on my stacklayout. If i press it, the items at the picker are shown, and i can select one. So far so good.

However i want to show it without having to press it, that is, for instance if i have an option at the tabbar, and i press it, i want the picker to show.
How can i achieve this?

Thank you!

What is the Xamarin Forms equivalent to Android: CameraCharacteristics.GetPhysicalCameraIds

$
0
0

I am trying to use Android.Camera2 in the Android portion of a Xamarin Forms app. It is largely working. Now it was brought to my attention that there are Logical Camera Devices which may or may not contain Physical Camera Devices.

In this page:
https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#getPhysicalCameraIds()

under android.hardware.camera2.CameraCharacteristics.getPhysicalCameraIds() it says:
Returns the set of physical camera ids that this logical CameraDevice is made up of.

So, in my code I get a cameraCharacteristics by:
characteristics = cameraManager.GetCameraCharacteristics(id);
where id is a logical camera Id which I got from:
string[] cameraIds = cameraManager.GetCameraIdList();

And there I do not see anything about getPhysicalCameraIds().

What am I missing here? Any insight is much appreciated.

Is there a solution to disable inner scrolling of Listview within a Scrollview?

$
0
0

Here is the layout I want to achieve:

I would like to scroll the entire screen instead of the listview.

I know bindable stacklayout is a good alternative as listview, but since I have to show group data, I didn't manage to make it work with bindable stacklayout.

What I tried but didn't work:
Try 1:
Put the listview and a boxview in the same grid. It did disable scrolling, but the listview won't be able to show full data in itemsource. It only shows the size of the screen.

Try 2 - custom renderer:
https://riptutorial.com/xamarin-forms/example/10022/custom-renderer-for-listview

neither ios nor android is working....

I found this post mentioned:
listView.HeightRequest = listView.RowHeight * ((Your List that you want to show in ListView).Count + 1);

But seems like I can only get the count of item(it will be dynamic) in viewmodel, then how to set listview's height?

So I think the best solution is still to disable to scroll of listview. Is there a workaround?

Preventing screen sleep on certain pages

$
0
0

Hi!

I have an app with a barcodescanner. When I open this barcodescanner (which is simply a contentpage), I want to prevent the screen going off/to sleep.

Does someone know how to prevent the screen sleep in Xamarin Forms (Android & iOS)? And if possible, only for one contentpage?

[UWP] How to remove right margin from tabbed pages?

$
0
0

I followed the answer provided here https://forums.xamarin.com/discussion/73426/remove-tabbedpage-padding-on-uwp-xamarin-forms to remove margins from tabbed page. But, now there seems to be margin added only on the right side of the page. Or maybe it is just left aligned?

This is my style:

<Style TargetType="PivotItem">
            <Setter Property="Background" Value="{ThemeResource PivotItemBackground}" />
            <!--<Setter Property="Margin" Value="{ThemeResource PivotItemMargin}" />-->
            <Setter Property="Margin" Value="0,0,0,0" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="PivotItem">
                        <Grid Background="{TemplateBinding Background}" HorizontalAlignment="Center" VerticalAlignment="{TemplateBinding VerticalAlignment}">

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="Pivot">
                                    <VisualState x:Name="Right" />
                                    <VisualState x:Name="Left" />
                                    <VisualState x:Name="Center" />

                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                ContentTemplate="{TemplateBinding ContentTemplate}"
                Content="{TemplateBinding Content}"
                Margin="{TemplateBinding Padding}" />

                        </Grid>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

@NMackay , could you help me with this problem?

using a jar in a xamarin.android binding give me an error?

$
0
0

It tells that

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 CS0738 '“AMapOptionsCreator”不实现接口成员“IParcelableCreator.CreateFromParcel(Parcel?)”。“AMapOptionsCreator.CreateFromParcel(Parcel)”无法实现“IParcelableCreator.CreateFromParcel(Parcel?)”,因为它没有“Object”的匹配返回类型。 AmapBinding C:\Users\Administrator\source\repos\AmapBinding\obj\Debug\generated\src\Com.Amap.Api.Maps2d.AMapOptionsCreator.cs 10 活动

I have added the jar package to the jars folder

reusable error view with a ContentView, how to set the Image source?

$
0
0

I'm trying to create a reusable error view control with a ContentView, to display the errors related to API calls like no network, timeout, server issue, ...

This view will contain: an image, a title and a small description. In my case, the image is based on a FontImageSource.

My ErrorControl view looks like this:

<ContentView.Content>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackLayout BackgroundColor="Transparent"
                     Spacing="0"
                     VerticalOptions="Center">
            <Grid>
                <Image Style="{StaticResource ErrorImageIconPart1Style}">
                    <Image.Source>
                        <FontImageSource Glyph="{StaticResource FadsIconNoInternetPart1}"
                                         Color="{StaticResource BlondColor}"
                                         FontFamily="FontAwesomeDuotoneSolid"
                                         Size="90" />
                    </Image.Source>
                </Image>
            </Grid>
            <Label Text="{Binding Description, Source={x:Reference ErrorControl}}" />
        </StackLayout>
        <Button Grid.Row="1"
                Text="Retry" />
    </Grid>
</ContentView.Content>

The I use my control like this:

<ctrl:ErrorView Title="Title Test"
                Description="Description Test"/>

If I have a static image this works fine, but I need to change the Glyph used by FontImageSource, depending of the error kind.

What sould be the better approach to achieve this?
- I've thought to use Converters, but as I have at least 3 kinds of error, it doesn't seem to be a good approach as I would have to create 3 converters
- I've also thought to use DataTemplate, but my image is not contained in a Collection/List, so this doesn't seem to request to my needs


ICommand not works

$
0
0

Hi, with this implementation my button in viewmodel is always disabled

in xaml i do
Command="{Binding SaveNewCustomerCommand}"
CommandParameter="{Binding NewCustomer}"

If i simply return true in CanExecute the Execute method works
but i cant implement CanExecute: is always disabled

`
public class SaveNewCustomerCommand : ICommand
{
public NewCustomerViewModel ViewModel { get; set; }

    public SaveNewCustomerCommand(NewCustomerViewModel newCustomerViewModel)
    {
        ViewModel = newCustomerViewModel;
    }

    public event EventHandler CanExecuteChanged;

    public bool CanExecute(object parameter)
    {
        var newCustomer = (NewCustomer)parameter;

        if (newCustomer == null) return false;

        if (string.IsNullOrEmpty(newCustomer.Name
            || string.IsNullOrEmpty(newCustomer.Email)
            )
            return false;

        return true;
    }

    public void Execute(object parameter)
    {
        var customer = (NewCustomer)parameter;

        ViewModel.SaveNewCustomer(customer);
    }`

Scandit xamarin forms sample

$
0
0

I have tried barcode scan with Scandit. I have found only Xamarin native sample app for Scandit. does anyone have Xamarin forms sample link for Scandit barcode.

on Shell Tabbar 5 icons how to change on the middle of icon size and color then the other 4 icon?

$
0
0

ı have android shell renderer that I could change all icon size

public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
bottomView.ItemIconSize = 80;
}

Total are 5 icons on Tabbar..I would like to change only middle of icon size larger and color on shellrenderer for anroid and ios?

thanks for solution...

Handling events in a controltemplate

$
0
0

I'm trying to handle an event on a control in a ControlTemplate. I'm using the ControlTemplate as a way of creating a custom navigation page. I've design a few controls within the header in the ControlTemplate and I've added a TapGesture to my back button image which routes to a method in the page class. I've tried doing this multiple ways but I simply can't get it to fire an event. Firstly, I tried adding the ControlTemplate to the App.xaml file with an event declared in App.xaml.cs - no event fired.

I then tried creating another ContentPage with its own ControlTemplate with a TapGesturizer declared in that class. No event fired. I then tried getting hold of the Image control in the constructor of the page (which I managed to do), so I could programmatically add the Tap Gesturizer. No event fired.

Does anyone have any idea of how to handle an event defined within a ControlTemplate? Ben on this for 3 days now and one step short of pulling my hair out!

Thanks

The return type of a methods?

$
0
0

I add a jar file to xamarin.android project and there is some error.

“AMapOptionsCreator” do not implements “IParcelableCreator.NewArray(int)”。

but it really did implemented it.

[Register ("newArray", "(I)[Lcom/amap/api/maps/AMapOptions;", "GetNewArray_IHandler")]
        public virtual unsafe global::Com.Amap.Api.Maps.AMapOptions[] NewArray (int p0)
        {
            const string __id = "newArray.(I)[Lcom/amap/api/maps/AMapOptions;";
            try {
                JniArgumentValue* __args = stackalloc JniArgumentValue [1];
                __args [0] = new JniArgumentValue (p0);
                var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, __args);
                return (global::Com.Amap.Api.Maps.AMapOptions[]) JNIEnv.GetArray (__rm.Handle, JniHandleOwnership.TransferLocalRef, typeof (global::Com.Amap.Api.Maps.AMapOptions));
            } finally {
            }
        }

The return type is extends from Java.Lang.Object.
If I change global::Com.Amap.Api.Maps.AMapOptions[] to Java.Lang.Object then it is ok. but I do not under stand the AmapOtions is extend from Java.Lang.Object why its return type is wrong?

How I make Custom MessageBox of Pin using Xamarin.form.GoogleMap Library

$
0
0

Using Xamarin.form.GoogleMap Library

hey guys, how i make custom message box for google map pin in xamarin forms?

like when i tapped on pin the my location and all other details show me ---->> how to make this custom ??

Is it possible to extract code from dev phone after debugging on phone?

$
0
0

So on Monday, my computer got stolen and I can't seem to find the backups I had. I do however have the phone I was developing on. I used it to preview the program as I went. I was wondering if there was a way to extract some of the code off of it somehow?

I have about a months worth of work lost because someone decided to break in and steal the whole computer and I think they may have taken the flashdrive I had backups on.. If I can extract even a little bit of it, it would save me tons of time. Thank you in advance!

PS. its an android if that matters.


How to determine an image's cropped coordinates to sample the original bytes?

$
0
0

Using Xamarin Forms, I have created a combined PinchToZoom and Pan Container that allows me to zoom and position an image within a viewport - the viewport is just the pinch to zoom and pan container, which from the user's point of view is just the tool that allows them to select part of the image in a square..

The following boilerplate code (with my additions) illustrates the process, with the ICameraBoothService being my service that got the original bytes, which consumes the latest data coordinates each time there is a pinch and zoom, and this means that when I dismiss this modal page, I can go back to the original image byte[] and apply some sort of activity to extract the cropped byte-set into a new image.:

public class PinchToZoomContainer : ContentView
    {
        private ICameraBoothService _cbs;

        // pinch
        double currentScale = 1;
        double startScale = 1;
        double xOffset = 0;
        double yOffset = 0;

        double xCoord;
        double yCoord;

        // pan
        bool blnDisableMove = false;

        public PinchToZoomContainer()
        {
            _cbs = SimpleIoc.Default.GetInstance<ICameraBoothService>("Default");

            var pinchGesture = new PinchGestureRecognizer();
            pinchGesture.PinchUpdated += OnPinchUpdated;
            GestureRecognizers.Add(pinchGesture);

            var panGesture = new PanGestureRecognizer();
            panGesture.PanUpdated += OnPanUpdated;
            GestureRecognizers.Add(panGesture);
        }

        void OnPanUpdated(object sender, PanUpdatedEventArgs e)
        {
            if (Content.Scale == 1)
            {
                return;
            }

            switch (e.StatusType)
            {
                case GestureStatus.Running:

                    if (!blnDisableMove)
                    {
                        Content.TranslationX = Math.Max(Math.Min(0, xOffset + (e.TotalX * Scale)), -Math.Abs((Content.Width * Content.Scale) - Application.Current.MainPage.Width));
                        Content.TranslationY = Math.Max(Math.Min(0, yOffset + (e.TotalY * Scale)), -Math.Abs((Content.Height * Content.Scale) - Application.Current.MainPage.Height));
                    }

                    break;

                case GestureStatus.Completed:

                    if (blnDisableMove)
                    {
                        blnDisableMove = false;
                        return;
                    }
                    // Store the translation applied during the pan
                    xOffset = Content.TranslationX;
                    yOffset = Content.TranslationY;
                    break;
            }

            Debug.WriteLine("Panning");
            OnUpdated();
        }
        private bool _subscribedImageSizeChanged;
        private CachedImage _cachedImage;
        private void OnUpdated()
        {
            _cbs.EnableSelect();
            _cbs.LoadTransformation(Content.Height, Content.Width, xOffset, yOffset, currentScale, startScale);
            //var temp = this.Content;
            Debug.WriteLine("______________________________");
            Debug.WriteLine($"Content Height: {Content.Height}");
            Debug.WriteLine($"Content Width: {Content.Width}");
            Debug.WriteLine($"Image Height: {((Image)Content).Height}");
            Debug.WriteLine($"Image Width: {((Image)Content).Width}");
            Debug.WriteLine($"xOffset: {xOffset}");
            Debug.WriteLine($"xOffset: {yOffset}");
            Debug.WriteLine($"currentScale: {currentScale}");
            Debug.WriteLine($"startScale: {startScale}");
            Debug.WriteLine("______________________________");

        }

        void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)
        {
            if (e.Status == GestureStatus.Started)
            {
                // Store the current scale factor applied to the wrapped user interface element,
                // and zero the components for the center point of the translate transform.
                startScale = Content.Scale;
                Content.AnchorX = 0;
                Content.AnchorY = 0;
            }
            if (e.Status == GestureStatus.Running)
            {
                // Calculate the scale factor to be applied.
                currentScale += (e.Scale - 1) * startScale;
                currentScale = Math.Max(1, currentScale);

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the X pixel coordinate.
                double renderedX = Content.X + xOffset;
                double deltaX = renderedX / Width;
                double deltaWidth = Width / (Content.Width * startScale);
                double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;

                // The ScaleOrigin is in relative coordinates to the wrapped user interface element,
                // so get the Y pixel coordinate.
                double renderedY = Content.Y + yOffset;
                double deltaY = renderedY / Height;
                double deltaHeight = Height / (Content.Height * startScale);
                double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;

                // Calculate the transformed element pixel coordinates.
                double targetX = xOffset - (originX * Content.Width) * (currentScale - startScale);
                xCoord = targetX;
                double targetY = yOffset - (originY * Content.Height) * (currentScale - startScale);
                yCoord = targetY;
                // Apply translation based on the change in origin.
                Content.TranslationX = targetX.Clamp(-Content.Width * (currentScale - 1), 0);
                Content.TranslationY = targetY.Clamp(-Content.Height * (currentScale - 1), 0);

                // Apply scale factor
                Content.Scale = currentScale;
            }
            if (e.Status == GestureStatus.Completed)
            {
                // Store the translation delta's of the wrapped user interface element.
                xOffset = Content.TranslationX;
                yOffset = Content.TranslationY;
            }

            Debug.WriteLine("Pinching");
            OnUpdated();
        }
    }

The following line merely passes the latest state back to where the original image came from:

_cbs.LoadTransformation(Content.Height, Content.Width, xOffset, yOffset, currentScale, startScale);

It is inside that service that I want to apply a process to the original image bytes and crop from the x and y coordinate of the top left hand position of the viewport, for the width of the view port, taking into account how the mage has been scaled.

The following would be easy, if I could determine the x,y coord, and width (using https://www.nuget.org/packages/Xamarin.Plugin.ImageEdit/):

var image = await CrossImageEdit.Current.CreateImageAsync(copy);

image.Crop(an x coord, a y coord, a calculated width, a calculated height);

However it seems to me that the data I have to play with is insufficient for me to apply this to the original image.

Any ideas on how to do this - even if I have to start again.

Forms Droid build causes System.OutOfMemoryException

$
0
0

We have a rather large project involving a number of external packages and components. During the droid build I've noticed a warning from the file "Xamarin.Android.Common.Targets"
Severity Code Description Project File Line Source Suppression State Warning Exception of type 'System.OutOfMemoryException' was thrown. at Microsoft.Cci.Pdb.MsfDirectory..ctor(PdbReader reader, PdbFileHeader head, BitAccess bits) at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, BitAccess bits, Boolean readAllStrings) at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Boolean readAllStrings) at Pdb2Mdb.Converter.Convert(String filename) at Xamarin.Android.Tasks.ConvertDebuggingFiles.Execute() ResponseGUI.Droid C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1550 Build

which points too:
<Target Name="_ConvertPdbFiles" Inputs="@(_ResolvedPdbFiles)" Outputs="@(_ResolvedPdbFiles->'%(RootDir)%(Directory)%(Filename).dll.mdb')" DependsOnTargets="_CollectPdbFiles"> <ConvertDebuggingFiles Files="@(_ResolvedPdbFiles)" /> </Target>

disabling gesture recognizer for a span in a label

$
0
0

I have a label inside a frame, the frame is clickable and the label contains a clickable link, before adding the gesture recognizer to the span that contains the link the whole frame was clickable including over the label but when I added the gesture recognizer for the span that contains the link now the link works but the frames gesture recognizer doesnt work when clicking over the label (on the text thats not a link), it still works when I click on the padding (not over the label but still inside the frame) so is there a way to still have the clicks over the text thats not a link to register as a click on the frame? adding the gesture recognizer on the span that contains the link kind of disabled clicking on the rest of the text. thanks in advance! (Im using c# and not xaml)

DataBinding Error No Property, Bindable Property or Event Found

$
0
0

Hey Guys,

i want to make a Bindable Property but i get this Error:
No Property, Bindable Property or Event Found

in Xaml:
Checked="{Binding NoticeUserData}"

in my class:
public static BindableProperty CheckboxProperty =
BindableProperty.Create(nameof(Checked), typeof(bool), typeof(Checkbox), true);

public bool Checked
{
get
{
return (bool)GetValue(CheckboxProperty);
}
set
{
SetValue(CheckboxProperty, value);
}
}

What do i miss? Can anyone help me i have never done before a databinding Property.

Thanks for help!

Converters or behaviors?

$
0
0

I need to show some formatted text, like a phone number or check number. Until now, I was using converters for that task and it's working, but today I was introduced to "Behaviors".
Looks like more simple for what I want (let the user type the numbers, show them in the format I need, and bind to the ViewModel formated), but the code looks more complex than using Converters (at least, for my noob eyes).

So, I want to know when to use converters and when to use bindings, pros and cons. I was looking for some article about it, but I can't find anything.

Thank you.

Viewing all 77050 articles
Browse latest View live


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