3

I have 2 pages, In first page when I click one of the item in listview, it should navigate to 2nd page and here in 2nd page snow particles are appeared.

After that, when I click back button, as usual it goes to first page and again when I click any of the listview items it navigates to 2nd page snow particles disappear,It just show a black screen.

Here are the codes:

For snow rendering I have two classes

First one

public class SnowScene : CCScene
{
    CCParticleSnow snow;

    public SnowScene(CCGameView gameView) : base(gameView)
    {
        var layer = new CCLayer();
        layer.Color=new CCColor3B(new CCColor4B(20,30,50,10));

        snow = new CCParticleSnow(new CCPoint(490, 20));
        snow.Position = new CCPoint(490 / 2, 800 + 1);
        snow.StartColor = new CCColor4F(CCColor4B.White);
        snow.EndColor = new CCColor4F(CCColor4B.Red);
        snow.StartSize = 15f;
        snow.StartSizeVar = 2f;
        snow.EndSize = 8f;
        snow.EndSizeVar = 1f;
        snow.Speed = 5f;
        snow.Gravity = new CCPoint(0.5f, -2);
        snow.EmissionRate = 3.5f;
        snow.Life = 50f;

        layer.AddChild(snow);
        this.AddLayer(layer);
    }
}

Second one

public class SnowyBackground : ContentView
{
    SnowScene overallScene;

    public SnowyBackground()
    {
        var sharpView = new CocosSharpView
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand
        };

        sharpView.ViewCreated += (sender, e) =>
        {
            var ccGView = sender as CCGameView;

            if (ccGView != null)
            {
                ccGView.DesignResolution = new CCSizeI(490, 800);
                overallScene = new SnowScene(ccGView);
                ccGView.RunWithScene(overallScene);
            }
        };

        Content = sharpView;
    }

}

And in Xaml in Second page Now When I click an Item of listview in first page(page1) like below: Event handler for Listview item click in first page-

async void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
{
    try
    {
        await Navigation.PushModalAsync(new Page2(),false);
    }
    catch(Exception ex)
    { }
}

2nd page -

<?xml version="1.0" encoding="utf-8"?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:Particle" 
    x:Class="Particle.ParticlePage">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <local:SnowyBackgroundView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.RowSpan="2" />

</Grid>

It navigates to page 2 and it successfully shows snow rendering. But when I repeat same steps... I mean If I click back button in page 2,then it goes to page1 and here when again I click lictview item,it goes to second page, but it doesnot show snow rendering, just a black screen.

uncle_scrooge
  • 409
  • 1
  • 5
  • 28
  • Hi @uncle_scrooge! Can you edit the question and copy/paste the source code for Page1 & Page2? – Brandon Minnick Apr 18 '18 at 23:10
  • @BrandonMinnick-thanks for reply.Its just 2 page.In first page one Listview is there..in the item clicked event like above code i am just navigating to second page through pushmodal async where(2nd page) I am just initializing the snowbackgroundview class..and its working for first time,but in second time its not working – uncle_scrooge Apr 19 '18 at 04:55
  • Hey Uncle Scrooge! Please copy/paste the source code for Page1 and Page2 into the question so that we can help solve your bug! – Brandon Minnick Apr 19 '18 at 05:02
  • @BrandonMinnick-I have edited the question and pasted both pages codes. – uncle_scrooge Apr 19 '18 at 05:13
  • @BrandonMinnick-Are you able to reproduce the issue.. – uncle_scrooge Apr 19 '18 at 07:22
  • Sorry, I am not able to reproduce the issue. I need to see both Xaml and Xaml.cs code for Page1 and Page2 and all associated view models to help further. – Brandon Minnick Apr 20 '18 at 19:27
  • Ok..I have created a simple test project for you,If you can fix the issue..it will be really helpful to me..https://1drv.ms/u/s!AgLAtkS5ABsAhIZrhbnF94U5SnChnQ – uncle_scrooge Apr 21 '18 at 13:16
  • Great! You've created a [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)! Please remove the existing code in the question and copy/paste the code for the test project in the question. I am wary of downloading `rar` files from unknown sources. – Brandon Minnick Apr 21 '18 at 20:20
  • I think..you are not interested in giving answer..just wasting time..I have written all fo the codes above..then i have given full source code,how without opening rar files you are saying minimal,complete example..anyways..it as simple as such...in first page there is a button ...in second page snow rendering classes are there(above codes).... – uncle_scrooge Apr 22 '18 at 03:01
  • That’s fair. Hopefully someone else will be able to solve your problem! – Brandon Minnick Apr 22 '18 at 03:14
  • @BrandonMinnick-great...thanks..... – uncle_scrooge Apr 22 '18 at 03:41
  • In the Line 'await Navigation.PushModalAsync(new Page2(),false);' You are creating a new instance of the Page2, have you tried to keep the reference when its created the first time and reuse it when you navigate again? – LittleBit Apr 25 '18 at 07:20
  • @LittleBit,but when I create new instance of page 2,it suppose to create a new instance of snowbackgroundview class as well,it should work as usual like it worked when it created first time – uncle_scrooge Apr 25 '18 at 09:13
  • @uncle_scrooge I have programmed an Application which navigated through different ViewModels/Pages and got the same error-behavior like yours. And like you, i thought this should work, but it doesent. It was fixed by disposing the old ViewModel and create a new one or reuising the old one. Therefore i thought this may solves your Problem. – LittleBit Apr 25 '18 at 09:24
  • ok..can you please create a sample for me..i am really frustrated on this... – uncle_scrooge Apr 25 '18 at 14:40
  • @uncle_scrooge - I downloaded your test.rar file, cleaned the solution, tried to build but got an error about a package. So, I updated the NuGet packages. It builds now and I was able to run it on an android emulator. I was not able to reproduce your issue though. Everytime I click the button, it takes me to a screen with your snow particles on a black background. I hit the back button and then click the button again but it always works. A few times it has taken 4-5 seconds before the snow appears though.. – J.H. Apr 25 '18 at 15:04

0 Answers0