Forum Xamarin Xamarin.Forms

ISVisible Property

AlbertoCAlbertoC ITMember ✭✭

Hi folks,

here my problem:

i have this xaml



behind it this piece of code available when i click a button

GridAct.IsVisible = true;
viewModel.RicalculateList();
GridAct.IsVisible = false;

the grid is not visible andthe property is true only when i change the code in this way

Device.BeginInvokeOnMainThread(() => {
//API calls to load lists

GridAct.IsVisible = true;
});

viewModel.RicalculateList();
GridAct.IsVisible = false;

but if i try to put the other two lines inside nothing works

advices...

Best Answer

Answers

  • JohnHardmanJohnHardman GBUniversity admin

    @AlbertoC - To get your post to format correctly, put three back ticks on the line before each piece of code and three back ticks on the line after each piece of code. In case you need to copy/paste it, there is a back tick after this colon:`

  • AlbertoCAlbertoC ITMember ✭✭
    edited March 2018

    Here the xaml code

    <Grid x:Name="GridAct" Margin="10,0" Grid.Row="2" Grid.ColumnSpan="2" IsVisible="False">
    <ActivityIndicator x:Name="Activity" IsRunning="true" VerticalOptions="Center" HorizontalOptions="Center" ``````Color="{ StaticResource Primary }" IsVisible="True"/>
    </Grid>

  • JohnHardmanJohnHardman GBUniversity admin

    @AlbertoC - Those aren't back ticks :-)

    On a UK keyboard, the back tick is on the key below the Esc key (to the left of the 1 key). As your keyboard may have a different layout, you can copy the back tick from my previous post.

  • AlbertoCAlbertoC ITMember ✭✭

    I have done

  • JohnHardmanJohnHardman GBUniversity admin

    @AlbertoC - Can you apply the same formatting to show the code behind that works and the code behind that doesn't work.

    Also, is there anything in viewModel.RicalculateList() that starts a new Task or performs an asynchronous operation?

  • AlbertoCAlbertoC ITMember ✭✭

    Method recalculatelist

    public void RicalculateList()
    {
    ListGen.Clear();

            List<veDocumenti> Docs = App.CurrentApp.iMioOrderDB.database.Table<veDocumenti>().Where(t => t.Eserc == Anno).ToList();
    
            List<genAnag> dataa = App.CurrentApp.iMioOrderDB.database.Table<genAnag>().ToList();
    
    
            genAnag Anag;
    
            foreach (var item in Docs.Where(z => z.Dt.Month == 1).ToList())
            {
                Anag = dataa.Where(x => x.IdAnag == item.IdAnag).FirstOrDefault();
                CustomizeList i = new CustomizeList(item, item.IdDoc, Anag);
                ListGen.Add(i);
            }
    
        }
    
  • AlbertoCAlbertoC ITMember ✭✭

    Work

    private void Applica_Clicked(object sender, EventArgs e)
        {
            Device.BeginInvokeOnMainThread(() => {
    
                GridAct.IsVisible = true;
    
            });
    
                viewModel.RicalculateList();
                GridAct.IsVisible = false;
    

    }

    not Work

    private void Applica_Clicked(object sender, EventArgs e)
        {
            Device.BeginInvokeOnMainThread(() => {
    
                GridAct.IsVisible = true;
    
            });
    

    Device.BeginInvokeOnMainThread(() => {

                viewModel.RicalculateList();
                GridAct.IsVisible = false;
    
            });
    

    }

  • JohnHardmanJohnHardman GBUniversity admin
    edited March 2018

    @AlbertoC - I'm still unclear as to what you are trying to achieve. Are you trying to display an ActivityIndicator whilst the list is being recalculated, and then remove the ActivityIndicator after the recalculation is complete? If so, you need to do the recalculation on a non-UI thread and only once it is complete then use the UI thread to set IsVisible = false.

  • AlbertoCAlbertoC ITMember ✭✭

    yes the goal is that one you said

Sign In or Register to comment.