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