@@ -1517,8 +1517,21 @@ protected override Size MeasureContent(double widthConstraint, double heightCons
1517
1517
}
1518
1518
}
1519
1519
1520
+ double width = double . IsFinite ( widthConstraint ) ? widthConstraint : 0 ;
1521
+ // To update width when loaded expander inside HorizontalStackLayout and AbsoluteLayout.
1522
+ if ( width == 0 )
1523
+ {
1524
+ #if ! WINDOWS
1525
+ var scaledScreenSize = new Size ( DeviceDisplay . MainDisplayInfo . Width / DeviceDisplay . MainDisplayInfo . Density , DeviceDisplay . MainDisplayInfo . Height / DeviceDisplay . MainDisplayInfo . Density ) ;
1526
+ #else
1527
+ var scaledScreenSize = new Size ( 300 , 300 ) ;
1528
+ #endif
1529
+ double scaledWidth = Math . Min ( scaledScreenSize . Width , scaledScreenSize . Height ) ;
1530
+ width = scaledWidth ;
1531
+ }
1532
+
1520
1533
_expanderHeight = _headerMeasuredSize . Height + _contentMeasuredSize . Height + ( _headerMeasuredSize . Height > 0 ? Padding . Bottom : 0 ) ;
1521
- return new Size ( widthConstraint , _expanderHeight ) ;
1534
+ return new Size ( width , _expanderHeight ) ;
1522
1535
}
1523
1536
1524
1537
@@ -1679,7 +1692,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
1679
1692
var oldHeader = oldValue as View ;
1680
1693
1681
1694
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1682
- if ( bindable is SfExpander expander )
1695
+ if ( bindable is SfExpander expander && expander . IsViewLoaded )
1683
1696
{
1684
1697
expander . OnHeaderChanged ( newHeader , oldHeader ) ;
1685
1698
}
@@ -1694,7 +1707,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
1694
1707
static void OnHeaderIconPositionPropertyChanged ( BindableObject bindable , object oldValue , object newValue )
1695
1708
{
1696
1709
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1697
- if ( bindable is SfExpander expander )
1710
+ if ( bindable is SfExpander expander && expander . IsViewLoaded )
1698
1711
{
1699
1712
expander . OnHeaderIconPositionChanged ( ( ExpanderIconPosition ) newValue , ( ExpanderIconPosition ) oldValue ) ;
1700
1713
}
@@ -1749,7 +1762,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
1749
1762
static void OnHeaderIconColorPropertyChanged ( BindableObject bindable , object oldValue , object newValue )
1750
1763
{
1751
1764
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1752
- if ( bindable is SfExpander expander )
1765
+ if ( bindable is SfExpander expander && expander . IsViewLoaded )
1753
1766
{
1754
1767
expander . OnIconColorChanged ( ( Color ) oldValue , ( Color ) newValue ) ;
1755
1768
}
@@ -1767,12 +1780,14 @@ private static void OnAnimationDurationPropertyChanged(BindableObject bindable,
1767
1780
if ( expander != null && ( double ) newValue == 0 && expander . _expanderAnimation != null )
1768
1781
{
1769
1782
var animation = expander . _expanderAnimation ;
1770
- if ( animation . AnimationManager != null )
1771
- // While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
1772
- // Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
1773
- animation . AnimationManager . Remove ( animation ) ;
1774
- expander . AnimationCompleted ( ) ;
1775
- expander . InvalidateForceLayout ( ) ;
1783
+ if ( animation . AnimationManager != null )
1784
+ {
1785
+ // While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
1786
+ // Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
1787
+ animation . AnimationManager . Remove ( animation ) ;
1788
+ expander . AnimationCompleted ( ) ;
1789
+ expander . InvalidateForceLayout ( ) ;
1790
+ }
1776
1791
}
1777
1792
}
1778
1793
0 commit comments