|  | 
|  | 1 | +using System.ComponentModel; | 
|  | 2 | +using System.Runtime.CompilerServices; | 
|  | 3 | + | 
|  | 4 | +namespace AuroraControls.TestApp; | 
|  | 5 | + | 
|  | 6 | +public partial class SetSvgIconExtensionsTestPage : ContentPage | 
|  | 7 | +{ | 
|  | 8 | +    private readonly string[] _svgIcons = { "logo.svg", "splatoon.svg", "triforce.svg", "dollar_sign.svg", "more.svg" }; | 
|  | 9 | +    private readonly double[] _sizes = { 16d, 24d, 32d, 48d, 64d }; | 
|  | 10 | +    private int _currentIconIndex; | 
|  | 11 | +    private bool _useColorOverride; | 
|  | 12 | +    private double _currentSize = 24d; | 
|  | 13 | +    private int _currentSizeIndex = 1; // Start with 24px | 
|  | 14 | + | 
|  | 15 | +    public SetSvgIconExtensionsTestPage() | 
|  | 16 | +    { | 
|  | 17 | +        InitializeComponent(); | 
|  | 18 | +        BindingContext = this; | 
|  | 19 | +        InitializeIcons(); | 
|  | 20 | +        SetupToolbarItems(); | 
|  | 21 | +    } | 
|  | 22 | + | 
|  | 23 | +    private void InitializeIcons() | 
|  | 24 | +    { | 
|  | 25 | +        // Test Button.SetSvgIcon() with different parameters | 
|  | 26 | +        TestButton1.SetSvgIcon("logo.svg"); | 
|  | 27 | +        TestButton2.SetSvgIcon("splatoon.svg", 32d); | 
|  | 28 | +        TestButton3.SetSvgIcon("triforce.svg", 24d, Colors.Blue); | 
|  | 29 | + | 
|  | 30 | +        // Test ImageButton.SetSvgIcon() with different parameters | 
|  | 31 | +        TestImageButton1.SetSvgIcon("dollar_sign.svg"); | 
|  | 32 | +        TestImageButton2.SetSvgIcon("more.svg", 48d); | 
|  | 33 | +        TestImageButton3.SetSvgIcon("logo.svg", 40d, Colors.Green); | 
|  | 34 | + | 
|  | 35 | +        // Test Image.SetSvgIcon() with different parameters | 
|  | 36 | +        TestImage1.SetSvgIcon("triforce.svg"); // Default size (24px) | 
|  | 37 | +        TestImage2.SetSvgIcon("splatoon.svg", 48d); // Custom size | 
|  | 38 | +        TestImage3.SetSvgIcon("dollar_sign.svg", 32d, Colors.Red); // Custom size and color | 
|  | 39 | + | 
|  | 40 | +        UpdateStatus("Icons initialized with various SetSvgIcon() configurations"); | 
|  | 41 | +    } | 
|  | 42 | + | 
|  | 43 | +    private void SetupToolbarItems() | 
|  | 44 | +    { | 
|  | 45 | +        // Test ToolbarItem.SetSvgIcon() | 
|  | 46 | +        var toolbarItem1 = new ToolbarItem { Text = "Tool 1" }; | 
|  | 47 | +        toolbarItem1.SetSvgIcon("logo.svg"); | 
|  | 48 | +        toolbarItem1.Clicked += OnToolbarItemClicked; | 
|  | 49 | + | 
|  | 50 | +        var toolbarItem2 = new ToolbarItem { Text = "Tool 2" }; | 
|  | 51 | +        toolbarItem2.SetSvgIcon("more.svg", 24d, Colors.Purple); | 
|  | 52 | +        toolbarItem2.Clicked += OnToolbarItemClicked; | 
|  | 53 | + | 
|  | 54 | +        ToolbarItems.Add(toolbarItem1); | 
|  | 55 | +        ToolbarItems.Add(toolbarItem2); | 
|  | 56 | + | 
|  | 57 | +        // Test Page.SetSvgIcon() - Set icon for this page | 
|  | 58 | +        this.SetSvgIcon("triforce.svg"); | 
|  | 59 | +    } | 
|  | 60 | + | 
|  | 61 | +    private void OnButtonClicked(object sender, EventArgs e) | 
|  | 62 | +    { | 
|  | 63 | +        if (sender is Button button) | 
|  | 64 | +        { | 
|  | 65 | +            UpdateStatus($"Button clicked: {button.Text}"); | 
|  | 66 | +        } | 
|  | 67 | +    } | 
|  | 68 | + | 
|  | 69 | +    private void OnImageButtonClicked(object sender, EventArgs e) | 
|  | 70 | +    { | 
|  | 71 | +        UpdateStatus("ImageButton clicked"); | 
|  | 72 | +    } | 
|  | 73 | + | 
|  | 74 | +    private void OnToolbarItemClicked(object sender, EventArgs e) | 
|  | 75 | +    { | 
|  | 76 | +        if (sender is ToolbarItem toolbarItem) | 
|  | 77 | +        { | 
|  | 78 | +            UpdateStatus($"ToolbarItem clicked: {toolbarItem.Text}"); | 
|  | 79 | +        } | 
|  | 80 | +    } | 
|  | 81 | + | 
|  | 82 | +    private void OnShowContextMenuClicked(object sender, EventArgs e) | 
|  | 83 | +    { | 
|  | 84 | +        // Create context menu with MenuItem.SetSvgIcon() | 
|  | 85 | +        var menuItem1 = new MenuFlyoutItem { Text = "Menu Item 1" }; | 
|  | 86 | +        menuItem1.SetSvgIcon("logo.svg", 20d); | 
|  | 87 | +        menuItem1.Clicked += (_, _) => UpdateStatus("Context Menu Item 1 clicked"); | 
|  | 88 | + | 
|  | 89 | +        var menuItem2 = new MenuFlyoutItem { Text = "Menu Item 2" }; | 
|  | 90 | +        menuItem2.SetSvgIcon("splatoon.svg", 20d, Colors.Orange); | 
|  | 91 | +        menuItem2.Clicked += (_, _) => UpdateStatus("Context Menu Item 2 clicked"); | 
|  | 92 | + | 
|  | 93 | +        var menuFlyout = new MenuFlyout(); | 
|  | 94 | +        menuFlyout.Add(menuItem1); | 
|  | 95 | +        menuFlyout.Add(menuItem2); | 
|  | 96 | + | 
|  | 97 | +        if (sender is Button button) | 
|  | 98 | +        { | 
|  | 99 | +            FlyoutBase.SetContextFlyout(button, menuFlyout); | 
|  | 100 | +        } | 
|  | 101 | + | 
|  | 102 | +        UpdateStatus("Context menu with SetSvgIcon() MenuItems created"); | 
|  | 103 | +    } | 
|  | 104 | + | 
|  | 105 | +    private void OnChangeIconsClicked(object sender, EventArgs e) | 
|  | 106 | +    { | 
|  | 107 | +        // Cycle through different icons | 
|  | 108 | +        _currentIconIndex = (_currentIconIndex + 1) % _svgIcons.Length; | 
|  | 109 | +        var newIcon = _svgIcons[_currentIconIndex]; | 
|  | 110 | + | 
|  | 111 | +        // Update all controls with new icons | 
|  | 112 | +        TestButton1.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.Purple : null); | 
|  | 113 | +        TestButton2.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.Teal : null); | 
|  | 114 | +        TestButton3.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.Orange : null); | 
|  | 115 | + | 
|  | 116 | +        TestImageButton1.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.Navy : null); | 
|  | 117 | +        TestImageButton2.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.Maroon : null); | 
|  | 118 | +        TestImageButton3.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.DarkGreen : null); | 
|  | 119 | + | 
|  | 120 | +        TestImage1.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.Crimson : null); | 
|  | 121 | +        TestImage2.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.DarkBlue : null); | 
|  | 122 | +        TestImage3.SetSvgIcon(newIcon, _currentSize, _useColorOverride ? Colors.DarkOrange : null); | 
|  | 123 | + | 
|  | 124 | +        UpdateStatus($"All icons changed to: {newIcon}"); | 
|  | 125 | +    } | 
|  | 126 | + | 
|  | 127 | +    private void OnToggleColorClicked(object sender, EventArgs e) | 
|  | 128 | +    { | 
|  | 129 | +        _useColorOverride = !_useColorOverride; | 
|  | 130 | +        OnChangeIconsClicked(sender, e); // Apply the color change | 
|  | 131 | +        UpdateStatus($"Color override: {(_useColorOverride ? "Enabled" : "Disabled")}"); | 
|  | 132 | +    } | 
|  | 133 | + | 
|  | 134 | +    private void OnChangeSizeClicked(object sender, EventArgs e) | 
|  | 135 | +    { | 
|  | 136 | +        _currentSizeIndex = (_currentSizeIndex + 1) % _sizes.Length; | 
|  | 137 | +        _currentSize = _sizes[_currentSizeIndex]; | 
|  | 138 | +        OnChangeIconsClicked(sender, e); // Apply the size change | 
|  | 139 | +        UpdateStatus($"Icon size changed to: {_currentSize}px"); | 
|  | 140 | +    } | 
|  | 141 | + | 
|  | 142 | +    private void UpdateStatus(string message) | 
|  | 143 | +    { | 
|  | 144 | +        StatusLabel.Text = $"{DateTime.Now:HH:mm:ss} - {message}"; | 
|  | 145 | +    } | 
|  | 146 | +} | 
0 commit comments