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

Chapter08 - ColorViewList : System.Reflection.TargetInvocationException

$
0
0

hi,

I am following this tutorial :

https://github.com/xamarin/xamarin-forms-book-samples/tree/master/Chapter08/ColorViewList

but when running the application I got the error : System.Reflection.TargetInvocationException

I think that the problem/errror message is related to some error in Xaml files:

https://github.com/xamarin/xamarin-forms-book-samples/blob/master/Chapter08/ColorViewList/ColorViewList/ColorViewList/ColorView.xaml

https://github.com/xamarin/xamarin-forms-book-samples/blob/master/Chapter08/ColorViewList/ColorViewList/ColorViewList/ColorViewListPage.xaml

can someone help me to solve this problem?

regards,
PCaridade

Microsoft Visual Studio Professional 2015 14.0.25431.01 Update 3
Visual Studio Tools for UWA 14.0.25527.01
Xamarin 4.2.0.719 (15694b9)
Xamarin.Android 7.0.1.6 (5a02b03)
Xamarin.iOS 10.2.0.4 (b638977)


ToolbarItem icon text properties

$
0
0

Hello, in Xamarin Forms, when I try to make a menu in the xaml file it does not show me the properties icon nor Text, let alone in the device nor in the emulator. I use ToolbarItem, who could help me.

Creating a Custom ViewRenderer As a Pass Through To Native Control

$
0
0

Hello,

I have native controls for iOS and Android that contain state and have methods. I would like to create a Xamarin.Forms View wrapper around these controls using a custom ViewRenderer. I would like to keep as much state in the native controls as possible, and simply use the XF View and ViewRenderer as a pass-through for method calls and fields.

The issue I have is that when a View is instantiated, a matching ViewRenderer is not created until the View is added to the UI tree. So this code works:

MyClassView v = new MyClassView();
myGrid.Children.Add(v); // renderer gets created behind the scenes here
v.DoAction1();

But not this code:

MyClassView v = new MyClassView();
v.DoAction1(); // no renderer yet, throws NullReferenceException
myGrid.Children.Add(v);

Here is the v1 implementation that exposes this problem:

namespace MyCustomNamespace
{
    public class MyClassView : View, IDisposable
    {
        private IMyClassRenderer renderer;

        public void DoAction1()
        {
            renderer.DoAction1();
        }

        internal void SetMyClassRenderer(IMyClassRenderer myClassRenderer)
        {
            this.renderer = myClassRenderer;
        }

        internal void TriggerLoadingStatusChanged(LoadingStatusChangedEventArgs e)
        {
            UpdateSomething();
        }
    }
}

using Internal = Com.My.Java.Namespace;
[assembly: ExportRenderer(typeof(MyClassView), typeof(Android.MyClassRenderer))]
namespace MyCustomNamespace.Android
{
    public class MyClassRenderer : ViewRenderer<MyClassView, Internal.MyClass>, IMyClassRenderer
    {
        public void DoAction1()
        {
            Control.DoAction1();
        }

        protected override void OnElementChanged(ElementChangedEventArgs<MyClass> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                SetNativeControl(new Internal.MyClass(Context));
                Element.SetMyClassRenderer(this);
            }

            if (e.OldElement != null)
            {
                Control.LoadingStatusChanged -= this.Control_LoadingStatusChanged;
            }

            if (e.NewElement != null)
            {
                Control.LoadingStatusChanged += this.Control_LoadingStatusChanged;
            }
        }

        private void Control_LoadingStatusChanged(object sender, Internal.LoadingStatusChangedEventArgs args)
        {
            Element.TriggerLoadingStatusChanged(new LoadingStatusChangedEventArgs(args.Status));
        }
    }
}

public IMyClassRenderer
{
    void DoAction1();
}

// JAVA CONTROL
public class MyClass extends FrameLayout
{
}

The solution I came up with is to create and set a renderer when in my View's constructor. This works, but gets messy when my View is added to the UI tree, and Xamarin creates another renderer. To preserve the state of my native control, I then grab the native control from the first renderer and give it to the second renderer, and have the first renderer unsubscribe to events form my native control.

Here is the v2 code for this solution:

namespace MyCustomNamespace
{
    public class MyClassView : View, IDisposable
    {
        private IMyClassRenderer renderer;

        internal object NativeControl;

        public MyClassView()
        {
            this.renderer = DependencyService.Get<IRendererHelper>().CreateAndSetRenderer(this);
        }

        public void DoAction1()
        {
            renderer.DoAction1();
        }

        internal void SetMyClassRenderer(IMyClassRenderer myClassRenderer)
        {
            if (this.renderer != null)
            {
                this.renderer.UnhookEvents();
            }

            this.renderer = myClassRenderer;
        }

        internal void TriggerLoadingStatusChanged(LoadingStatusChangedEventArgs e)
        {
            UpdateSomething();
        }
    }
}

using Internal = Com.My.Java.Namespace;
[assembly: ExportRenderer(typeof(MyClass), typeof(MyClassRenderer))]
namespace MyCustomNamespace.Android
{
    public class MyClassRenderer : ViewRenderer<MyClass, Internal.MyClass>, IMyClassRenderer
    {
        public void DoAction1()
        {
            Control.DoAction1();
        }

        protected override void OnElementChanged(ElementChangedEventArgs<MyClass> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                if (Element.NativeControl == null)
                {
                    SetNativeControl(new Internal.MyClass(Context));
                    Element.SetMyClassRenderer(this);
                    Element.NativeControl = this.Control;
                }
                else
                {
                    Internal.MyClass internalMyClass = Element.NativeControl as Internal.MyClass;
                    ((MyClassRenderer)internalMyClass.Parent).RemoveView(internalMyClass);
                    SetNativeControl((Internal.MyClass)Element.NativeControl);
                    Element.SetMyClassRenderer(this);
                }
            }

            if (e.OldElement != null)
            {
                Control.LoadingStatusChanged -= this.Control_LoadingStatusChanged;
            }

            if (e.NewElement != null)
            {
                Control.LoadingStatusChanged += this.Control_LoadingStatusChanged;
            }
        }

        private void Control_LoadingStatusChanged(object sender, Internal.LoadingStatusChangedEventArgs args)
        {
            Element.TriggerLoadingStatusChanged(new LoadingStatusChangedEventArgs(args.Status));
        }

        public void UnhookEvents()
        {
            Control.LoadingStatusChanged -= this.Control_LoadingStatusChanged;
        }
    }
}

[assembly: Xamarin.Forms.Dependency (typeof (RendererHelperImplementation))]
namespace MyCustomNamespace.Android
{
    internal class RendererHelperImplementation : IRendererHelper
    {
        public IMyClassRenderer CreateAndSetRenderer(View view)
        {
            var renderer = Platform.CreateRenderer(view);
            Platform.SetRenderer(view, renderer);

            return (IMyClassRenderer)renderer;
        }
    }
}

This seems to work, but boy oh boy does it feel inelegant. I also fear that some of the View <-> Renderer mapping that Xamarin normally takes care of will be incorrect due to my mucking around.

Does anyone know of a better solution to this problem?

Thanks,
Wyatt

How to solve unknown type in UWP app - Windows.UI.ViewManagement.StatusBar

$
0
0

Hi,
From what I can tell, I've got a pretty basic UWP app, but whenever I run it I get the following exception:

System.TypeLoadException was unhandled by user code
HResult=-2146233054
Message=Could not find Windows Runtime type 'Windows.UI.ViewManagement.StatusBar'.
Source=Xamarin.Forms.Platform.UAP
TypeName=Windows.UI.ViewManagement.StatusBar
StackTrace:
at Xamarin.Forms.Platform.UWP.Platform..ctor(Page page)
at Xamarin.Forms.Platform.UWP.WindowsPage.CreatePlatform()
at Xamarin.Forms.Platform.UWP.WindowsBasePage.LoadApplication(Application application)
at MyApp.UWP.MainPage..ctor()
at MyApp.UWP.My_App_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage()
at MyApp.UWP.My_App_UWP_XamlTypeInfo.XamlUserType.ActivateInstance()
InnerException:

I'm using Xamarin.Forms 2.1.0.6529 in my project. I also tried downloading a sample off GitHub (https://github.com/jamesmontemagno/MyWeather.Forms) and I'm seeing the same exception. Looks like that project is using 2.0.0.6490.

So, that makes this sound like something is missing from my system? I'm running Windows 10 which I just installed yesterday.

I'm new to UWP and Xamarin, so I don't even know where to start looking. I have noticed that if I comment out the line:

LoadApplication(new MyApp.App());

the application boots. Of course, nothing is there since I'm not starting the app, but the code to init Xamarin.Forms is still running in App.xaml.cs.

Thanks,
Nick

Unable to Create ListView inside ListView Exception

$
0
0

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle


<ListView.ItemTemplate>



<ListView.ItemTemplate>



</ListView.ItemTemplate>



</ListView.ItemTemplate>

How can we add Calendar in Xamarin.forms for Windows Platform and schedule events on selected dates.

How to add a SAP project to a PCL one?

$
0
0

I am starting to learn Xamarin.Forms (and C#) using visual studio trying to replicating each chapter of the Creating Mobile Apps with Xamarin.Forms book. I have currently a (probably dumb and easy to fix) doubt.

In chapter 9 (Monkey With Sound) an SAP project containing just a class is needed into a my current solution containing a PCL, and I do not know how to do this.

If I make right click on my solution -> add -> new project , and add either Blank App (Native Shared) or Blank App (Xamarin.forms Shared) it creates a new base project along with each platform.

How can I add just a SAP project where I can add my class?

Thank you.

Push notification is not received:error (Tag expression can not contain more than 20 operands)

$
0
0

I want to send notification to multiple user using notification hub.if I send collection of 20 tags, I receive the push notification but if I send more than 20 tags of collection then , I am getting exception Tag expression can not contain more than 20 operands
Can anyone tell me that how many push notification I can send at a time ?


How to close MasterDetailPage

$
0
0

Hi All,
I want to write an event which will close the MasterDetailPage.
Currently there is a default back button which works correctly but I want to write a command which will close it.
I am wrapping a NavigationPage inside a MasterDetailPage.
Any help will will be highly appreciated.
Thanks In advance

How to load embedded image resource in PCL assembly?

$
0
0

My PCL assembly (named "Foo.Bar") contains a folder "Images" which contains an image file "check_yellow_24.png" (build action = EmbeddedResource). I'm trying to set this image as the source of an Image control. The image control doesn't display the image, ostensibly because the resource is not found at run time. This is how I'm setting the image source:

imgSelected.Source = ImageSource.FromResource("Foo.Bar.Images.check_yellow_24.png");

I've read the document Working with Images and confirmed the image isn't found at run time by viewing the output of the following diagnostic code fragment. The only discovered embedded resources are the assembly's .xaml files.

// Display names of embedded resources
var assembly = typeof(SomeClassDefinedInTheAssembly).GetTypeInfo().Assembly;
foreach (var res in assembly.GetManifestResourceNames())  {
    System.Diagnostics.Debug.WriteLine(">>> " + res);
}

What do I need to do to successfully retrieve the embedded image resource for use by the containing assembly?

Controls for Image gallery

$
0
0

Hi,

migtht be a simple question but I am looking for a suitable control to show images like an image gallery.

The images should be shown next to each other in one "row" until the display screens wraps the following images to the next row.
Each image should be selected/clicked to show the full screen image on the next page.

Sounds simple, but I could not figure out what control to use best.

I tried a simple ListView, but it is row centric. Even if I tried to put more than one image in the ViewCell.....it is no great solution. I have to define the number of images per ViewCell so it does not wrap automatically and I am not able to select a single image.

Like this
http://blog.masterdevs.com/xf-day-3/

I also used the DevExpress Grid

https://components.xamarin.com/view/devexpress-grid

Seems to be a powerful component and I was able to display a grid with > 500 images....BUT also one image per row.

I know this is the purpose of those controls but what control or XAML code should I use to have more image per row dynamically ?

Any ideas ?

Thank you

Marco

Accessing ResourceDictionary from xaml to c# programmatically

$
0
0

How do I access the contents of my ResourceDictionary that is located my App.xaml page?

I am trying to make a label's text color that uses a color in my resource dictionary with key = "textColor"

var colorLabel = new Label { Text = "colored Text ", TextColor = (Color) Resources["textColor"]};

Gives me a null error

How do I implement a list of planned Local Notifications using XF and Dependency Service?

$
0
0

Hello all.

I am developing a "calendar app" where I need to be able to schedule a list of future calendar events and show local notifications when these events are to occur. During user setup, the user choose to be notified if a specific calendar event should occur. During this setup a list of events on specific future dates are created, and I need to schedule the notifications for each event showing the user information about event object.

I am using Xamarin.Forms, Dependency Services and have defined an ILocalNotificationService interface in my PCL and implemented this Interface in each of my plattform projects. I think this is the way to go, but I can't figure out how to implement future notifications on Android (for starters).

Now I am trying to use the Alarm Manager and a BroadcastReceiver that initiates a notificationCompat.Builder in its OnReceive method from the alarm. But when doing this I loose the information I want to show the user about the specific event object in my event list.

Are there anyone out there facing the same problems, or more hopefully, have any of you implemented this kind of functionality and would like to share your solution?

Thanks in advance!

Regards Paal Christian

Enhancing Xamarin.Forms ListView with Grouping Headers: Bind itemTemplate to whole List

$
0
0

@JamesMontemagno

I need to bind a whole List which I grouped by a string, following JamesMontemagnos exmaple, to a ItemTemplate.
What is the right key word to bind this property of an ObservableCollection. By now I tried:

<ListView.ItemTemplate>
  <DataTemplate>
   <cells:SentenceCell List="{Binding Items}"/>
  </DataTemplate>
 </ListView.ItemTemplate>

As u see I am using a Custom Renderer for my ViewCell which is capable of binding a list.

James Montemagno's example:
motzcod.es/post/94643411707/enhancing-xamarinforms-listview-with-grouping

How to save upcoming event in calendar and show notification on that day.

$
0
0
Hi , I am new in xamarin , I want to save upcoming events in calendar. Dates through datepicker and events name through Entry, and want to display a notification on that day with messages which I save through Entry, for Windows and Android Platform.
Please share any solution.

Best Network library for Xamarin Forms

$
0
0

I am very beginner for Xamarin development.

I want to know which best network library in Xamarin Forms.

Any one suggest me..

Note: I already check the RestSharp library but it only available for platform dependent code. But I want for Xamarin Forms

Xamarin.Froms CodeDom

$
0
0

Hi there,

Is it possible to use the System.CodeDom with Xamarin.Forms?
I included

using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;

in my project, but when I try to use any of CodeDom's classes in my class, they aren't recognized.

why mvvmcross?

$
0
0

I am keep hearing and reading mvvmcross for xamarin. I have experience mvvm with wpf and can i just use it as use it on wpf? What makes mvvmcross easier or is there something which i cant achieve with mvvm that i can only achieve with mvvmcross? can I somebody shed some lights on this?

thanks you very much

M2MQTT in Xamarin forms or Xamarin Android

$
0
0

i am unable to Integrate the M2MQTT in xamarin forms or Xamarin Android .

I am using RelayCommand, the command works perfectly but does not update the ListView

$
0
0

Xaml:

<ListView x:Name="ListaDev" ItemsSource="{Binding Devices, Mode=TwoWay}">
            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                  <ViewCell.View>

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



                  <Button
                    Image="removeicon.png"
                    Command="{Binding Path=RemoveItemListViewDevices, Source={StaticResource viewModel}"
                    CommandParameter="{Binding .}"
                    Grid.Row="0"
                    Grid.Column="0"
                    Grid.ColumnSpan="7"
                    HorizontalOptions="End"/>

ViewModel:

    public RemoveItemListViewDevices RemoveItemListViewDevices { get; set; }
    private ObservableCollection _devices = new ObservableCollection();
    public ObservableCollection<Device> Devices
    {
        get { return _devices; }
        set
        {
            _devices = value;
            OnPropertyChanged();
        }
    }
public void Delete(object parameter)
{
var item = parameter as Device;

        Debug.WriteLine("Id: " + item.Id.ToString());

        Debug.WriteLine("Before: " + Devices.Count().ToString());
        _devices.RemoveAt((item.Id));
        Debug.WriteLine("After: " + Devices.Count().ToString());
    }

Output:

[0:] Id: 4
01-06 13:19:28.231 D/Mono ( 2761): Assembly Ref addref Base[0xb9634290] -> System.Linq[0xb96571a0]: 6
[0:] Before: 5
[0:] After: 4

Viewing all 91519 articles
Browse latest View live