Skip to content

Commit e4791c5

Browse files
committed
Added documenting sample for content templating in Marquee control
1 parent 970ddc1 commit e4791c5

File tree

5 files changed

+87
-7
lines changed

5 files changed

+87
-7
lines changed

components/Marquee/samples/Marquee.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,10 @@ The repeat behavior determines how many times the marquee will loop before the a
4343

4444
The default direction is left, meaning the content will move leftwards, but this can be changed to right, up, or down. Direction changed between left and right or up and down are handled continously, meaning that the animation will resume from its current position if changed between these directions.
4545

46+
> [!Sample MarqueeTextSample]
47+
48+
## Non-Text Content
49+
50+
It is possible to use non-text content in the Marquee control. However templating must be used because the control will need to be duplicated for the looping animation.
51+
4652
> [!Sample MarqueeSample]

components/Marquee/samples/MarqueeSample.xaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
<StackPanel Padding="16">
1212
<controls:Marquee Behavior="{x:Bind ConvertStringToMarqueeBehavior(MQBehavior), Mode=OneWay}"
13-
Direction="{x:Bind ConvertStringToMarqueeDirection(MQDirection), Mode=OneWay}"
14-
FontSize="18"
15-
RepeatBehavior="Forever"
16-
Speed="{x:Bind MQSpeed, Mode=OneWay}">
13+
Direction="{x:Bind ConvertStringToMarqueeDirection(MQDirection), Mode=OneWay}"
14+
FontSize="18"
15+
RepeatBehavior="Forever"
16+
Speed="{x:Bind MQSpeed, Mode=OneWay}"
17+
Content="This is a demonstration of using templating to added non-text content to the Marquee control.">
1718
<controls:Marquee.ContentTemplate>
18-
<DataTemplate>
19-
<Button Content="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."/>
19+
<DataTemplate x:DataType="x:String">
20+
<Button Content="{x:Bind}"/>
2021
</DataTemplate>
2122
</controls:Marquee.ContentTemplate>
2223
</controls:Marquee>
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
<Project>
1+
<Project>
22
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))')" />
33
<PropertyGroup>
44
<ToolkitComponentName>Marquee</ToolkitComponentName>
55
</PropertyGroup>
66

77
<!-- Sets this up as a toolkit component's sample project -->
88
<Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" />
9+
<ItemGroup>
10+
<Compile Update="MarqueeTextSample.xaml.cs">
11+
<DependentUpon>MarqueeTextSample.xaml</DependentUpon>
12+
</Compile>
13+
</ItemGroup>
14+
<ItemGroup>
15+
<Compile Update="MarqueeSample.xaml.cs">
16+
<DependentUpon>MarqueeSample.xaml</DependentUpon>
17+
</Compile>
18+
</ItemGroup>
919

1020
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
2+
<Page x:Class="MarqueeExperiment.Samples.MarqueeTextSample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="MarqueeExperiment.Samples"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<StackPanel Padding="16">
12+
<controls:Marquee Behavior="{x:Bind ConvertStringToMarqueeBehavior(MQBehavior), Mode=OneWay}"
13+
Direction="{x:Bind ConvertStringToMarqueeDirection(MQDirection), Mode=OneWay}"
14+
FontSize="18"
15+
RepeatBehavior="Forever"
16+
Speed="{x:Bind MQSpeed, Mode=OneWay}"
17+
Content="{x:Bind MQText, Mode=OneWay}"/>
18+
</StackPanel>
19+
</Page>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
7+
namespace MarqueeExperiment.Samples;
8+
9+
[ToolkitSample(id: nameof(MarqueeTextSample), "Marquee", description: "A control for scrolling content in a marquee fashion.")]
10+
[ToolkitSampleNumericOption("MQSpeed", initial: 96, min: 48, max: 196, step: 1, Title = "Speed")]
11+
[ToolkitSampleMultiChoiceOption("MQDirection", "Left", "Right", "Up", "Down", Title = "Marquee Direction")]
12+
[ToolkitSampleTextOption("MQText", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")]
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 MarqueeTextSample : Page
20+
{
21+
public MarqueeTextSample()
22+
{
23+
this.InitializeComponent();
24+
}
25+
26+
private MarqueeBehavior ConvertStringToMarqueeBehavior(string str) => str switch
27+
{
28+
"Looping" => MarqueeBehavior.Looping,
29+
"Ticker" => MarqueeBehavior.Ticker,
30+
#if !HAS_UNO
31+
"Bouncing" => MarqueeBehavior.Bouncing,
32+
#endif
33+
_ => throw new System.NotImplementedException(),
34+
};
35+
36+
private MarqueeDirection ConvertStringToMarqueeDirection(string str) => str switch
37+
{
38+
"Left" => MarqueeDirection.Left,
39+
"Up" => MarqueeDirection.Up,
40+
"Right" => MarqueeDirection.Right,
41+
"Down" => MarqueeDirection.Down,
42+
_ => throw new System.NotImplementedException(),
43+
};
44+
}

0 commit comments

Comments
 (0)