Skip to content

Commit 6e5a70d

Browse files
authored
Merge branch 'main' into niels9001/per-heading-foreground
2 parents 5e24fd5 + c71cac4 commit 6e5a70d

31 files changed

+380
-223
lines changed

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Otherwise, you can clone the repo, open the `components` directory, navigate wit
2828
- [DataTable](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/DataTable/samples/DataTable.md)
2929
- [Extensions.DependencyInjection](https://github.com/CommunityToolkit/Labs-Windows/tree/main/components/Extensions.DependencyInjection)
3030
- [MarkdownTextBlock](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/MarkdownTextBlock/samples/MarkdownTextBlock.md)
31-
- [MarqueeText](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/MarqueeText/samples/MarqueeText.md)
31+
- [Marquee](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/Marquee/samples/Marquee.md)
3232
- [Notifications](https://github.com/CommunityToolkit/Labs-Windows/tree/main/components/Notifications)
3333
- [Ribbon](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/Ribbon/samples/Ribbon.md)
3434
- [RivePlayer](https://github.com/CommunityToolkit/Labs-Windows/blob/main/components/RivePlayer/samples/RivePlayer.md)

components/MarkdownTextBlock/src/HtmlWriter.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes)
3636
var myHyperlinkButton = new MyHyperlinkButton(node, renderer.Config.BaseUrl);
3737
myHyperlinkButton.ClickEvent += (sender, e) =>
3838
{
39-
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(((HyperlinkButton)sender).NavigateUri);
39+
var button = (HyperlinkButton)sender;
40+
var uri = button.NavigateUri;
41+
var handled = renderer.MarkdownTextBlock.RaiseLinkClickedEvent(uri);
42+
if (handled)
43+
{
44+
button.NavigateUri = null;
45+
}
4046
};
4147
hyperLink = myHyperlinkButton;
4248
}
@@ -46,7 +52,12 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes)
4652
myHyperlink.TextElement.Foreground = renderer.Config.Themes.LinkForeground;
4753
myHyperlink.ClickEvent += (sender, e) =>
4854
{
49-
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
55+
var uri = sender.NavigateUri;
56+
var handled = renderer.MarkdownTextBlock.RaiseLinkClickedEvent(uri);
57+
if (handled)
58+
{
59+
sender.NavigateUri = null;
60+
}
5061
};
5162
hyperLink = myHyperlink;
5263
}

components/MarkdownTextBlock/src/LinkClickedEventArgs.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace CommunityToolkit.WinUI.Controls;
77
public class LinkClickedEventArgs : EventArgs
88
{
99
public Uri Uri { get; }
10+
/// <summary>
11+
/// Set to true in your handler to indicate the link click was handled and default navigation should be suppressed.
12+
/// </summary>
13+
public bool Handled { get; set; }
1014

1115
public LinkClickedEventArgs(Uri uri)
1216
{

components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ public partial class MarkdownTextBlock : Control
2323

2424
public event EventHandler<LinkClickedEventArgs>? OnLinkClicked;
2525

26-
internal void RaiseLinkClickedEvent(Uri uri) => OnLinkClicked?.Invoke(this, new LinkClickedEventArgs(uri));
26+
internal bool RaiseLinkClickedEvent(Uri uri)
27+
{
28+
if (OnLinkClicked == null)
29+
{
30+
return false;
31+
}
32+
var args = new LinkClickedEventArgs(uri);
33+
OnLinkClicked?.Invoke(this, args);
34+
return args.Handled;
35+
}
2736

2837
private static void OnConfigChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
2938
{

components/MarkdownTextBlock/src/Renderers/ObjectRenderers/Inlines/LinkInlineRenderer.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ protected override void Write(WinUIRenderer renderer, LinkInline link)
3333
var myHyperlinkButton = new MyHyperlinkButton(link, renderer.Config.BaseUrl);
3434
myHyperlinkButton.ClickEvent += (sender, e) =>
3535
{
36-
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(((HyperlinkButton)sender).NavigateUri);
36+
var button = (HyperlinkButton)sender;
37+
var uri = button.NavigateUri;
38+
var handled = renderer.MarkdownTextBlock.RaiseLinkClickedEvent(uri);
39+
if (handled)
40+
{
41+
// Suppress default navigation by clearing NavigateUri just for this invocation
42+
button.NavigateUri = null;
43+
// Optionally restore later; not needed unless reused.
44+
}
3745
};
3846
// Apply link foreground to nested RichTextBlock content
3947
// (Handled in MyHyperlinkButton initialization via MarkdownConfig.Default for now)
@@ -45,7 +53,13 @@ protected override void Write(WinUIRenderer renderer, LinkInline link)
4553
hyperlink.TextElement.Foreground = renderer.Config.Themes.LinkForeground;
4654
hyperlink.ClickEvent += (sender, e) =>
4755
{
48-
renderer.MarkdownTextBlock.RaiseLinkClickedEvent(sender.NavigateUri);
56+
var uri = sender.NavigateUri;
57+
var handled = renderer.MarkdownTextBlock.RaiseLinkClickedEvent(uri);
58+
if (handled)
59+
{
60+
// Suppress navigation by clearing NavigateUri
61+
sender.NavigateUri = null;
62+
}
4963
};
5064

5165
renderer.Push(hyperlink);
File renamed without changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Marquee
3+
author: Avid29
4+
description: A control for scrolling content in a marquee fashion.
5+
keywords: Marquee, Control
6+
dev_langs:
7+
- csharp
8+
category: Controls
9+
subcategory: Layout
10+
experimental: true
11+
discussion-id: 231
12+
issue-id: 426
13+
icon: Assets/Marquee.png
14+
---
15+
16+
The Marquee control allows text or other content to scroll in a marquee fashion. The control is heavily templated and many changes can be made by modifying the style. The control can also be adjusted using the Speed, Behavior, RepeatBehavior, and Direction properties.
17+
18+
## Speed
19+
20+
The speed property determines how quickly the content moves in pixels per second. The speed can be adjusted mid-animation and handled continously.
21+
22+
## Behavior
23+
24+
The Marquee control has 3 behaviors
25+
26+
### Ticker
27+
28+
Ticker mode starts with all content off the screen then scrolls the content across across the screen. When the animation finishes in the mode no content will be on screen.
29+
30+
### Looping
31+
32+
Looping mode will begin with the start of the content fully in frame then scroll towards the end. When the end is reached it will loop back to the start of the content. Nothing will happen if the content fits in frame.
33+
34+
### Bouncing
35+
36+
Looping mode will begin with the start of the content fully in frame then scroll towards the end. When the end is reached it will bounce and scroll backwards to the start of the content. Nothing will happen if the content fits in frame.
37+
38+
## RepeatBehavior
39+
40+
The repeat behavior determines how many times the marquee will loop before the animation finishes. It can be a number of iteration, a duration, or forever.
41+
42+
## Direction
43+
44+
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.
45+
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+
52+
> [!Sample MarqueeSample]
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. 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.MarqueeSample"
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="using: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+
Content="{x:Bind Data}"
14+
Direction="{x:Bind ConvertStringToMarqueeDirection(MQDirection), Mode=OneWay}"
15+
FontSize="18"
16+
RepeatBehavior="Forever"
17+
Speed="{x:Bind MQSpeed, Mode=OneWay}">
18+
<controls:Marquee.ContentTemplate>
19+
<DataTemplate x:DataType="local:MarqueeSampleItems">
20+
<ItemsControl ItemsSource="{x:Bind Items}">
21+
<ItemsControl.ItemsPanel>
22+
<ItemsPanelTemplate>
23+
<StackPanel Orientation="Horizontal"
24+
Spacing="8" />
25+
</ItemsPanelTemplate>
26+
</ItemsControl.ItemsPanel>
27+
<ItemsControl.ItemTemplate>
28+
<DataTemplate x:DataType="local:MarqueeSampleItem">
29+
<Border Width="100"
30+
Height="48"
31+
Background="{x:Bind Brush}">
32+
<TextBlock Text="{x:Bind Name}" />
33+
</Border>
34+
</DataTemplate>
35+
</ItemsControl.ItemTemplate>
36+
</ItemsControl>
37+
</DataTemplate>
38+
</controls:Marquee.ContentTemplate>
39+
</controls:Marquee>
40+
41+
<Button Click="AddItem_Click"
42+
Content="Add something" />
43+
</StackPanel>
44+
</Page>

0 commit comments

Comments
 (0)