|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using CommunityToolkit.WinUI.Controls; |
| 6 | +using Windows.UI; |
| 7 | + |
| 8 | +namespace MarqueeExperiment.Samples; |
| 9 | + |
| 10 | +[ToolkitSample(id: nameof(MarqueeSample), "Marquee", description: "A control for scrolling content in a marquee fashion.")] |
| 11 | +[ToolkitSampleNumericOption("MQSpeed", initial: 96, min: 48, max: 196, step: 1, Title = "Speed")] |
| 12 | +[ToolkitSampleMultiChoiceOption("MQDirection", "Left", "Right", "Up", "Down", Title = "Marquee Direction")] |
| 13 | +//[ToolkitSampleMultiChoiceOption("MarqueeRepeat", "Repeat", "Forever", "1x", "2x")] |
| 14 | +#if !HAS_UNO |
| 15 | +[ToolkitSampleMultiChoiceOption("MQBehavior", "Ticker", "Looping", "Bouncing", Title = "Marquee Behavior")] |
| 16 | +#else |
| 17 | +[ToolkitSampleMultiChoiceOption("MQBehavior", "Ticker", "Looping", Title = "Marquee Behavior")] |
| 18 | +#endif |
| 19 | +public sealed partial class MarqueeSample : Page |
| 20 | +{ |
| 21 | + public MarqueeSample() |
| 22 | + { |
| 23 | + this.InitializeComponent(); |
| 24 | + |
| 25 | + for (int i = 0; i < 15; i++) |
| 26 | + { |
| 27 | + AddItem_Click(this, null); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + private MarqueeBehavior ConvertStringToMarqueeBehavior(string str) => str switch |
| 32 | + { |
| 33 | + "Looping" => MarqueeBehavior.Looping, |
| 34 | + "Ticker" => MarqueeBehavior.Ticker, |
| 35 | +#if !HAS_UNO |
| 36 | + "Bouncing" => MarqueeBehavior.Bouncing, |
| 37 | +#endif |
| 38 | + _ => throw new NotImplementedException(), |
| 39 | + }; |
| 40 | + |
| 41 | + public MarqueeSampleItems Data = new(); |
| 42 | + |
| 43 | + private MarqueeDirection ConvertStringToMarqueeDirection(string str) => str switch |
| 44 | + { |
| 45 | + "Left" => MarqueeDirection.Left, |
| 46 | + "Up" => MarqueeDirection.Up, |
| 47 | + "Right" => MarqueeDirection.Right, |
| 48 | + "Down" => MarqueeDirection.Down, |
| 49 | + _ => throw new NotImplementedException(), |
| 50 | + }; |
| 51 | + |
| 52 | + private void AddItem_Click(object sender, RoutedEventArgs? e) |
| 53 | + { |
| 54 | + var rand = new Random(); |
| 55 | + Data.Items.Add(new MarqueeSampleItem() |
| 56 | + { |
| 57 | + Name = $"Item {Data.Items.Count + 1}", |
| 58 | + Brush = new SolidColorBrush(Color.FromArgb(255, (byte)rand.Next(256), (byte)rand.Next(256), (byte)rand.Next(256))), |
| 59 | + }); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +public class MarqueeSampleItems |
| 64 | +{ |
| 65 | + public ObservableCollection<MarqueeSampleItem> Items { get; } = new(); |
| 66 | +} |
| 67 | + |
| 68 | +public record MarqueeSampleItem |
| 69 | +{ |
| 70 | + public string? Name { get; set; } |
| 71 | + |
| 72 | + public Brush? Brush { get; set; } |
| 73 | +} |
0 commit comments