Can't add System.Timers as an assembly reference for CarouselLayout?

I'm trying to use CarouselLayout from this source but when I copy some of the code into my Xamarin.Forms project, I can't seem to get a reference to System.Timers that's needed in CarouselLayout control. So there's an error at using System.Timers; when I bring the code into my project, but when I open the project by itself, it works just fine.

When I search for the reference, nothing shows up that matches, in fact it seems I'm unable to find any other references to System libraries to anything else. My PCL project is targeting .NET Framework 4.5 and Windows 8.

This is where my lack of C# experience comes in and I'm probably missing something very elementary...

Best Answers

Answers

  • @JasonAwbrey Thanks Jason, I modified the code and it seems to work. But I also noticed in the stackoverflow page that was referenced also had an update that .NET Framework 4.5.1 now supports System.Timer, but when I tried to target 4.5.1 I get the message that "The following will be automatically targeted because they support the same set of portable APIs: .NET Framework 4.5" so it just reverts to 4.5 anyway... any idea why this is happening?

  • FilipTodorovicFilipTodorovic USMember
    edited August 2015

    @JasonAwbrey So I tried to replace the timer function with the code you provided from the comment on the site, but now I'm having the app break every time. So these are the areas that had the System.Timer originally:

    Constructor:
    public Carousel() {
    // Layouts and Content setting

            _selectedItemTimer = new Timer
        {
            AutoReset = false,
            Interval = 300
        };
    
        _selectedItemTimer.Elapsed += SelectedItemTimerElapsed;
        }
    

    Other functions using Timer:
    void UpdateSelectedItem ()
    {
    _selectedItemTimer.Stop();
    _selectedItemTimer.Start();
    }

        void SelectedItemTimerElapsed()
        {
        SelectedItem = SelectedIndex > -1 ? Children[SelectedIndex].BindingContext : null;
        }
    

    And then this bindable property is using UpdateSelectedItem:
    public static readonly BindableProperty SelectedIndexProperty =
    BindableProperty.Create<CarouselLayout, int> (
    carousel => carousel.SelectedIndex,
    0,
    BindingMode.TwoWay,
    propertyChanged: (bindable, oldValue, newValue) => {
    ((CarouselLayout)bindable).UpdateSelectedItem ();
    }
    );

    So the code mentioned is similar to what SelectedItemTimerElapsed is doing so I figured just removing the _selectedItemTimer = new Timer section in the constructor and replacing it with the new Device.StartTimer event will do it, but it seems to break. I guess I'm just not really familiar with what is going on with the Timer, and not sure what to do with the SelectedIndexProperty. Any ideas?

  • SwathiSudarSwathiSudar USMember ✭✭

    I tried the countdown timer in the pcl project in Visual Studio I tried to Install Mobilist.AdvancedTimer.Plugin It couldn't install it shows like error message.

    I download the AdvancedTimerApp(portable ) the n Again shows below screen error

    then I get suggestion from Xamarin Senior
    I open my project in the Xamarin Studio and then Double click the projectname(pcl) then option window will be show and go to build-> general-> select the .Net4.5 - Profile 78 then click Apply
    go to Project package click Under Project (PCL -potable)-> AddPackage -> search What Package you require here Timer I required
    search - Mobilist.AdvancedTimer.Plugin
    Check the Mobilist.AdvancedTimer.Plugin
    click Okay
    then go to
    go to Project package click Under Project (Droid)-> AddPackage -> search What Package you require here Timer I required
    search - Mobilist.AdvancedTimer.Plugin
    Check the Mobilist.AdvancedTimer.Plugin
    click Okay
    then go to
    go to Project package click Under Project (iOS)-> AddPackage -> search What Package you require here Timer I required
    search - Mobilist.AdvancedTimer.Plugin
    Check the Mobilist.AdvancedTimer.Plugin
    click Okay
    then Run the Application it is working
    By the way I use Visual studio always but For easily add reference I switch to Xamarin Studio. Now I can use both the thing

Sign In or Register to comment.