Skip to content
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

🐞WinUI Crash #13

Open
Strypper opened this issue Jun 30, 2023 · 5 comments
Open

🐞WinUI Crash #13

Strypper opened this issue Jun 30, 2023 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed Windows

Comments

@Strypper
Copy link

Exception

Microsoft.UI.Xaml.Controls.Frame.NavigationFailed was unhandled.

Implementation

<?xml version="1.0" encoding="utf-8" ?>
<ContentView
    x:Class="MAUIsland.IosSwitchContentView"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:switch="clr-namespace:IeuanWalker.Maui.Switch;assembly=IeuanWalker.Maui.Switch"
    x:Name="root">
    <switch:CustomSwitch
        HeightRequest="40"
        HorizontalKnobMargin="1"
        IsToggled="{Binding IsToggled, Source={x:Reference root}}"
        KnobBackgroundColor="White"
        KnobHeight="36"
        KnobLimit="Boundary"
        KnobWidth="36"
        SemanticProperties.Hint="{Binding AccessibilityHint, Source={x:Reference root}}"
        SwitchPanUpdate="CustomSwitch_SwitchPanUpdate"
        Toggled="CustomSwitch_Toggled"
        ToggledCommand="{Binding ToggledCommand, Source={x:Reference root}}"
        WidthRequest="70">
        <switch:CustomSwitch.StrokeShape>
            <RoundRectangle CornerRadius="20" />
        </switch:CustomSwitch.StrokeShape>
        <switch:CustomSwitch.KnobStrokeShape>
            <RoundRectangle CornerRadius="18" />
        </switch:CustomSwitch.KnobStrokeShape>
        <switch:CustomSwitch.BackgroundContent>
            <Grid
                ColumnDefinitions="35,35"
                HeightRequest="40"
                WidthRequest="70">
                <Label
                    Grid.Column="0"
                    FontAttributes="Bold"
                    FontAutoScalingEnabled="False"
                    FontSize="12"
                    HorizontalOptions="Center"
                    Text=" |"
                    TextColor="White"
                    VerticalTextAlignment="Center" />
                <Label
                    Grid.Column="1"
                    FontAttributes="Bold"
                    FontAutoScalingEnabled="False"
                    FontSize="12"
                    HorizontalOptions="Center"
                    Text=""
                    TextColor="#BBBBBB"
                    VerticalTextAlignment="Center" />
            </Grid>
        </switch:CustomSwitch.BackgroundContent>
    </switch:CustomSwitch>
</ContentView>
using IeuanWalker.Maui.Switch;
using IeuanWalker.Maui.Switch.Events;
using IeuanWalker.Maui.Switch.Helpers;

namespace MAUIsland;

public partial class IosSwitchContentView : ContentView
{
    #region [ CTor ]

    public IosSwitchContentView()
    {
        InitializeComponent();
    }
    #endregion

    #region [ Properties ]
    public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(IosSwitchContentView), false, BindingMode.TwoWay);

    public bool IsToggled
    {
        get => (bool)GetValue(IsToggledProperty);
        set => SetValue(IsToggledProperty, value);
    }

    public static readonly BindableProperty AccessibilityHintProperty = BindableProperty.Create(nameof(AccessibilityHint), typeof(string), typeof(IosSwitchContentView), string.Empty);

    public string AccessibilityHint
    {
        get => (string)GetValue(AccessibilityHintProperty);
        set => SetValue(AccessibilityHintProperty, value);
    }

    public static readonly BindableProperty ToggledCommandProperty = BindableProperty.Create(nameof(ToggledCommand), typeof(ICommand), typeof(IosSwitchContentView));

    public ICommand ToggledCommand
    {
        get => (ICommand)GetValue(ToggledCommandProperty);
        set => SetValue(ToggledCommandProperty, value);
    }
    #endregion

    #region [ Event Handlers ]
    public event EventHandler<ToggledEventArgs>? Toggled = null;

    static void CustomSwitch_SwitchPanUpdate(CustomSwitch customSwitch, SwitchPanUpdatedEventArgs e)
    {
        //Color Animation
        Color fromColor = e.IsToggled ? Color.FromArgb("#4ACC64") : Color.FromArgb("#EBECEC");
        Color toColor = e.IsToggled ? Color.FromArgb("#EBECEC") : Color.FromArgb("#4ACC64");

        double t = e.Percentage * 0.01;

        customSwitch.BackgroundColor = ColorAnimationUtil.ColorAnimation(fromColor, toColor, t);
    }

    void CustomSwitch_Toggled(object sender, ToggledEventArgs e)
    {
        Toggled?.Invoke(sender, e);
    }
    #endregion
}
@IeuanWalker
Copy link
Owner

Reopening, if someone from the community wants to add windows support feel free to create a PR.
Only platform code is around accessibility.

Its not something ill be supporting personally, but happy for the community to add support/ maintain it

@IeuanWalker IeuanWalker reopened this Jun 30, 2023
@IeuanWalker IeuanWalker added enhancement New feature or request help wanted Extra attention is needed Windows labels Jun 30, 2023
@divyesh008
Copy link

divyesh008 commented Aug 9, 2024

It's the same for iOS as well, app crashes. It only works in Android and in that too it does not show Switch.
I have used it like this:

<switch:CustomSwitch
        HorizontalOptions="Start"
        IsToggled="{Binding CorrectOnSite}"
        BackgroundColor="{StaticResource MidGray}"
        KnobBackgroundColor="{StaticResource WhiteSmoke}" />

@IeuanWalker
Copy link
Owner

@divyesh008 can you create a repo, im actively using it in a number of production apps without an issue on iOS

@divyesh008
Copy link

Yes my bad, it did work in iOS but in Windows its crashing.

@IeuanWalker
Copy link
Owner

@divyesh008 sorry only iOS and Android is supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed Windows
Projects
None yet
Development

No branches or pull requests

3 participants