Skip to content

960628 - Application crashes when setting ItemSpacing and ExpandMode using Global Styling #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions maui/src/Accordion/AccordionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,6 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
// Content does not get collapsed when item is being collapsed in PCL view.
if (bindable is AccordionItem accordionItem)
{
if (accordionItem.Content != null && (bool)newValue && accordionItem.Content.IsVisible)
{
accordionItem.Content.IsVisible = true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle understanding why we are removing this 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bricefriha - This part of the code was not relevant to the current issue and has been removed, as it was unnecessary.

if (accordionItem._accordion != null && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
{
accordionItem.OnIsExpandedChanging((bool)newValue);
Expand Down
10 changes: 5 additions & 5 deletions maui/src/Accordion/SfAccordion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ internal override Size LayoutMeasure(double widthConstraint, double heightConstr
/// <param name="newValue">The new value of expand mode property. </param>
static void OnExpandModePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is SfAccordion accordion)
if (bindable is SfAccordion accordion && accordion.IsViewLoaded)
{
accordion.UpdateAccordionItemsBasedOnExpandModes(true);
}
Expand All @@ -1406,7 +1406,7 @@ static void OnExpandModePropertyChanged(BindableObject bindable, object oldValue
/// <param name="newValue">The new value of item spacing property. </param>
static void OnItemSpacingPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is SfAccordion accordion)
if (bindable is SfAccordion accordion && accordion.IsViewLoaded)
{
foreach (var item in accordion.Items)
{
Expand All @@ -1427,7 +1427,7 @@ static void OnItemSpacingPropertyChanged(BindableObject bindable, object oldValu
/// <param name="newValue">The new value of animation duration property. </param>
static void OnAnimationDurationPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is SfAccordion accordion)
if (bindable is SfAccordion accordion && accordion.IsViewLoaded)
{
foreach (AccordionItem item in accordion.Items)
{
Expand All @@ -1447,7 +1447,7 @@ static void OnAnimationDurationPropertyChanged(BindableObject bindable, object o
/// <param name="newValue">The new value of animation easing property. </param>
static void OnAnimationEasingPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is SfAccordion accordion)
if (bindable is SfAccordion accordion && accordion.IsViewLoaded)
{
foreach (AccordionItem item in accordion.Items)
{
Expand All @@ -1467,7 +1467,7 @@ static void OnAnimationEasingPropertyChanged(BindableObject bindable, object old
/// <param name="newValue">The new value of header icon position property. </param>
static void OnHeaderIconPositionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is SfAccordion accordion)
if (bindable is SfAccordion accordion && accordion.IsViewLoaded)
{
foreach (AccordionItem item in accordion.Items)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,68 @@ public void ItemsProperty_SetItems_TriggersOnItemsPropertyChanged()
Assert.Equal(2, itemsFromProperty.Count);
}

[Fact]
public void AccordionStyle_WhenApplied_SetsCorrectProperties()
{
// Arrange
var animationDuration = 100;
ExpanderAnimationEasing easing = new ExpanderAnimationEasing();
easing = ExpanderAnimationEasing.SinInOut;
ExpanderIconPosition expanderIconPosition = new ExpanderIconPosition();
expanderIconPosition = ExpanderIconPosition.Start;
var itemSpacing = 100;
AccordionExpandMode expandMode = new AccordionExpandMode();
expandMode = AccordionExpandMode.Multiple;
AccordionAutoScrollPosition autoScrollPosition = new AccordionAutoScrollPosition();
autoScrollPosition = AccordionAutoScrollPosition.MakeVisible;
var style = new Style(typeof(SfAccordion));
style.Setters.Add(new Setter
{
Property = SfAccordion.AnimationDurationProperty,
Value = animationDuration
});
style.Setters.Add(new Setter
{
Property = SfAccordion.HeaderIconPositionProperty,
Value = expanderIconPosition
});
style.Setters.Add(new Setter
{
Property = SfAccordion.AnimationEasingProperty,
Value = easing
});
style.Setters.Add(new Setter
{
Property = SfAccordion.ExpandModeProperty,
Value = expandMode
});
style.Setters.Add(new Setter
{
Property = SfAccordion.ItemSpacingProperty,
Value = itemSpacing
});
style.Setters.Add(new Setter
{
Property = SfAccordion.AutoScrollPositionProperty,
Value = autoScrollPosition
});
var resources = new ResourceDictionary();
resources.Add("AccordionStyle", style);
Application.Current = new Application();
Application.Current.Resources = resources;
var accordion = new SfAccordion();
// Act
accordion.Style = (Style)Application.Current.Resources["AccordionStyle"];
// Assert
Assert.Equal(animationDuration, accordion.AnimationDuration);
Assert.Equal(expanderIconPosition, accordion.HeaderIconPosition);
Assert.Equal(easing, accordion.AnimationEasing);
Assert.Equal(expandMode, accordion.ExpandMode);
Assert.Equal(animationDuration, accordion.AnimationDuration);
Assert.Equal(itemSpacing, accordion.ItemSpacing);
Assert.Equal(autoScrollPosition, accordion.AutoScrollPosition);
}

#endregion

#region Methods
Expand Down Expand Up @@ -1044,6 +1106,7 @@ public void OnHeaderIconPositionPropertyChanged_UpdatesIconPosition()
var accordionItem = new AccordionItem();
accordion.Items.Add(accordionItem);
accordionItem._accordionItemView = [];
accordion.IsViewLoaded = true;
accordion.HeaderIconPosition = ExpanderIconPosition.Start;
var oldValue = ExpanderIconPosition.End;
var newValue = ExpanderIconPosition.Start;
Expand All @@ -1070,6 +1133,7 @@ public void OnAnimationEasingPropertyChanged_UpdatesAnimationEasing(ExpanderAnim
var accordionItem = new AccordionItem();
accordion.Items.Add(accordionItem);
accordionItem._accordionItemView = [];
accordion.IsViewLoaded = true;
accordion.AnimationEasing = newValue;
MethodInfo? methodInfo = typeof(SfAccordion).GetMethod(
"OnAnimationEasingPropertyChanged",
Expand All @@ -1093,6 +1157,7 @@ public void OnAnimationDurationPropertyChanged_UpdatesAnimationDuration(int newV
var accordionItem = new AccordionItem();
accordion.Items.Add(accordionItem);
accordionItem._accordionItemView = [];
accordion.IsViewLoaded = true;
accordion.AnimationDuration = newValue;
MethodInfo? methodInfo = typeof(SfAccordion).GetMethod(
"OnAnimationDurationPropertyChanged",
Expand Down