Fix toggle switch content overflow bug

This commit is contained in:
chinboy
2025-09-29 00:08:06 +08:00
parent a745156294
commit 8cc34e230d
2 changed files with 14 additions and 23 deletions
@@ -8,7 +8,8 @@
<ControlTemplate>
<Panel>
<atom:WaveSpiritDecorator Name="{x:Static atom:ToggleSwitchThemeConstants.WaveSpiritPart}"/>
<Canvas Name="{x:Static atom:ToggleSwitchThemeConstants.MainContainerPart}">
<Canvas Name="{x:Static atom:ToggleSwitchThemeConstants.MainContainerPart}"
ClipToBounds="True">
<atom:SwitchKnob Name="{x:Static atom:ToggleSwitchThemeConstants.SwitchKnobPart}"
IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
IsCheckedState="{TemplateBinding IsChecked}" />
+12 -22
View File
@@ -267,6 +267,7 @@ public class ToggleSwitch : ToggleButton,
private CompositeDisposable? _onBindingDisposables;
private CompositeDisposable? _offBindingDisposables;
private WaveSpiritDecorator? _waveSpiritDecorator;
private Canvas? _mainLayout;
static ToggleSwitch()
{
@@ -353,32 +354,20 @@ public class ToggleSwitch : ToggleButton,
protected override Size ArrangeOverride(Size finalSize)
{
if (_switchKnob is not null)
_mainLayout?.Arrange(new Rect(DesiredSize));
if (!_isCheckedChanged)
{
if (!_isCheckedChanged)
{
_switchKnob.Arrange(KnobRect);
}
else
{
_switchKnob.Arrange(KnobMovingRect);
}
_switchKnob?.Arrange(KnobRect);
}
if (_offContentPresenter != null)
else
{
_offContentPresenter.Arrange(new Rect(new Point(OffContentOffset.X, OffContentOffset.Y), _offContentPresenter.DesiredSize));
}
if (_onContentPresenter != null)
{
_onContentPresenter.Arrange(new Rect(new Point(OnContentOffset.X, OnContentOffset.Y), _onContentPresenter.DesiredSize));
}
if (_waveSpiritDecorator != null)
{
_waveSpiritDecorator.Arrange(new Rect(DesiredSize));
_switchKnob?.Arrange(KnobMovingRect);
}
_offContentPresenter?.Arrange(new Rect(new Point(OffContentOffset.X, OffContentOffset.Y), _offContentPresenter.DesiredSize));
_onContentPresenter?.Arrange(new Rect(new Point(OnContentOffset.X, OnContentOffset.Y), _onContentPresenter.DesiredSize));
_waveSpiritDecorator?.Arrange(new Rect(DesiredSize));
return finalSize;
}
@@ -501,6 +490,7 @@ public class ToggleSwitch : ToggleButton,
_onContentPresenter = scope.Find<ContentPresenter>(ToggleSwitchThemeConstants.OnContentPresenterPart);
_offContentPresenter = scope.Find<ContentPresenter>(ToggleSwitchThemeConstants.OffContentPresenterPart);
_waveSpiritDecorator = e.NameScope.Find<WaveSpiritDecorator>(ToggleSwitchThemeConstants.WaveSpiritPart);
_mainLayout = e.NameScope.Find<Canvas>(ToggleSwitchThemeConstants.MainContainerPart);
HandleLoadingState(IsLoading);
}