У меня есть модель с именем CategoryTemplate , которая содержит vaseleCollection DropDownItems < /код>, который представляет подкатегории. Иерархия, на мой взгляд, (для простоты я ограничу количество SFExpanders 1) заключается в следующем: < /p>
Код: Выделить всё
Код: Выделить всё
< /code>
private void OnAccordionCollapsing(object sender_p, Syncfusion.Maui.Accordion.ExpandingAndCollapsingEventArgs e)
{
if(sender_p is SfAccordion _accordion && _accordion is not null)
{
SfExpander? _parentExpander = null;
SfExpander[]? expandersToCheck = [charsExpander, locsExpander, itemsExpander];
foreach (SfExpander expander in expandersToCheck)
{
if (expander.GetVisualTreeDescendants().Any(x => x == _accordion))
{
_parentExpander = expander;
break; // Found the parent, no need to continue searching
}
}
if (_parentExpander != null)
{
// Find the first SfAccordion within the parent expander
SfAccordion? firstAccordion = _parentExpander.GetVisualTreeDescendants()
.OfType()
.FirstOrDefault();
// If it is the first SfAccordion and it isn't null..
if (firstAccordion is not null && firstAccordion == _accordion)
{
// Make the other SfExpanders appear again because the first accordion's content has all been collapsed.
if (_parentExpander == charsExpander)
{
locsExpander.IsVisible = true;
itemsExpander.IsVisible = true;
}
else if (_parentExpander == locsExpander)
{
charsExpander.IsVisible = true;
itemsExpander.IsVisible = true;
}
else if (_parentExpander == itemsExpander)
{
charsExpander.IsVisible = true;
locsExpander.IsVisible = true;
}
}
else
{
Debug.WriteLine("The collapsing accordion is NOT the first accordion in the parent expander.");
}
}
else
{
Debug.WriteLine("No parent expander found.");
}
}
}
private void OnAccordionExpanding(object sender_p, Syncfusion.Maui.Accordion.ExpandingAndCollapsingEventArgs e)
{
if(sender_p is SfAccordion _accordion && _accordion is not null)
{
SfExpander _parentExpander;
SfExpander[]? expandersToCheck = [charsExpander, locsExpander, itemsExpander];
foreach (SfExpander expander in expandersToCheck)
{
if (expander.GetVisualTreeDescendants().Any(x => x == _accordion))
{
// Set all other SfExpanders to disappear
if(expander == charsExpander)
{
_parentExpander = charsExpander;
locsExpander.IsVisible = false;
itemsExpander.IsVisible = false;
}
else if(expander == locsExpander)
{
_parentExpander = locsExpander;
charsExpander.IsVisible = false;
itemsExpander.IsVisible = false;
}
else if(expander == itemsExpander)
{
_parentExpander = itemsExpander;
charsExpander.IsVisible = false;
locsExpander.IsVisible = false;
}
return;
}
Debug.WriteLine("No parent expander found.");
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... net-maui-9
Мобильная версия