wrong datafrom color, no realtime update

Eduardo Gomez 3,426 Reputation points
2022-03-17T13:53:07.147+00:00

Hello

I have pop-up, that I use for updating the Notebook, but the problem that I have, is that the name of the notebook updates in Realtime, but the color doesn't, and sometimes it's the wrong color

184069-20220317-144143.gif

   public EditNotebookPopUpPageModel() {  

        PageAppearCommand = new Command(PageAppearAction);  

        UpdateCommand = new Command(UpdateAction);  
    }  

    private async void UpdateAction() {  
        var color = SelectedColor.ToHex();  
        App.FirebaseService.UpdateNotebookAsync(Notebook.Id, color, Notebook.Name);  
        await App.FirebaseService.ReadAsync(AppConstant.Notebooks);  
        await PopupNavigation.Instance.PopAsync();  
    }  

    private void PageAppearAction() {  

        Notebook = Application.Current.Properties[AppConstant.SelectedNotebook] as Notebook;  
    }  

This class inherited from another class that implement Fody.

I am using this to update

  public async void UpdateNotebookAsync(string Id, string NotebookColor, string NotebookName) {  

        await firebaseClient  
            .Child(AppConstant.Notebooks)  
            .Child(Id)  
            .PatchAsync($"{<!-- -->{ \"Color\" : \"{NotebookColor}\", \"Name\" : \"{NotebookName}\" }}");  
    }  

This is the Xaml color part

        <ScrollView Grid.Row="2" Orientation="Horizontal">  
            <buttons:SfChipGroup ItemsSource="{Binding Colors}" SelectedItem="{Binding SelectedColor}">  
                <buttons:SfChipGroup.Behaviors>  
                    <community:EventToCommandBehavior Command="{Binding SelectedColorCommand}" EventName="SelectionChanged" />  
                </buttons:SfChipGroup.Behaviors>  
                <buttons:SfChipGroup.ItemTemplate>  
                    <DataTemplate>  
                        <StackLayout>  
                            <border:SfBorder Style="{StaticResource ColorBorderStyle}">  
                                <Ellipse  
                                    Fill="{Binding .}"  
                                    HeightRequest="60"  
                                    WidthRequest="60" />  
                            </border:SfBorder>  
                        </StackLayout>  
                    </DataTemplate>  
                </buttons:SfChipGroup.ItemTemplate>  
            </buttons:SfChipGroup>  
        </ScrollView>  

https://github.com/eduardoagr/DuoNotes

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,342 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 42,356 Reputation points Microsoft Vendor
    2022-03-18T02:35:00.453+00:00

    Hello,

    You need to modify public async void UpdateNotebookAsync to public async Task UpdateNotebookAsync in the 213 row of 'FirebaseService.cs'.

    Then you need to modify App.FirebaseService.UpdateNotebookAsync(Notebook.Id, color, Notebook.Name); to await App.FirebaseService.UpdateNotebookAsync(Notebook.Id, color, Notebook.Name); in the 33 row of EditNotebookPopUpPageModel.cs.

    After the above, the color of your DataForm will update at real-time.

    In general, async methods should use async task as much as possible, and async void is a “pseudo-asynchronous” wrapper. Unless, some background methods called by events cannot use Task directly. Use async void to wrap real async methods.

    You can refer to Async/Await - Best Practices in Asynchronous Programming to get more details.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.