if statement - Navigation to to a nested MudTabPanel within a conditional MudTabPanel? - Stack Overflow

admin2025-04-15  3

I have this conditional MudTab paneland want to navigate to the MemberCRMJournal with the methods at the bottom. The problem is that _membertabs stays null and doesn't get rendered.

            @if (_isEditMode && _userService.HasPermission(Permissions.UpdateMember))
            {
                <MudTabPanel Icon="@Icons.Material.Filled.Edit" Text="Mitglied">
                    <MudTabs @ref="_memberTabs">
                        <MudTabPanel Icon="@Icons.Material.Outlined.Person" Text="Mitgliedsdaten">
                            <ProfileTemplate ButtonNoText="Abbrechen" ButtonYesText="Speichern" User="@_editMember"
                            TemplateType="ProfileTemplateType.UPDATEMEMBER" SaveEvent="UpdateMemberAsync" Cancel="() => GoToTab(0)">
                            </ProfileTemplate>
                        </MudTabPanel>
                        <MudTabPanel Icon="@Icons.Material.Outlined.Security" Text="Berechtigungen">
                            <PrivacyData IsMemberOverview="true" UserMail="@_editMember?.EmailAddress"></PrivacyData>
                        </MudTabPanel>
                        <MudTabPanel Icon="@Icons.Material.Outlined.Public" Text="Öffentliches Profil">
                            <PublicProfile _user="@_editMember" SaveEvent="() => GoToTab(0)" Origin="MemberOverview"></PublicProfile>
                        </MudTabPanel>
                        <MudTabPanel Icon="@Icons.Material.Outlined.Notes" Text="Verlauf">
                            <MemberCRMJournal MemberId="@_memberId"></MemberCRMJournal>
                        </MudTabPanel>
                    </MudTabs>
                </MudTabPanel>
            }
private async Task GoToTab(int index, int? subIndex = null)
{
    _overviewTabs?.ActivatePanel(index);
    await Task.Delay(10);
    if (subIndex.HasValue && _memberTabs != null)
    {
        _memberTabs.ActivatePanel(subIndex.Value);
    }
}

private async void ShowJournalTab(long memberId)
{
    _isEditMode = true;
    _memberId = memberId;
    await GoToTab(1, 3); 
}

It actually worked at the start and stopped working after some code changes that have nothing to do with this logic (to the ebst of ym knowledge).

I tried it with a larger delay and to use await InvokeAsync(StateHasChanged) but that didn't help. If i remove the if condition ne navigation to the tab also works.

转载请注明原文地址:http://www.anycun.com/QandA/1744731294a86826.html