Skip to content

Commit 5ab106e

Browse files
Merge branch 'main' into ryken100/feature-AttachedShadows
2 parents c932579 + fe9ac89 commit 5ab106e

36 files changed

+3263
-9
lines changed

Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
</PackageReference>
112112
-->
113113
<PackageReference Include="Microsoft.UI.Xaml">
114-
<Version>2.6.1</Version>
114+
<Version>2.6.2</Version>
115115
</PackageReference>
116116
<PackageReference Include="Monaco.Editor">
117117
<Version>0.7.0-alpha</Version>
@@ -274,6 +274,7 @@
274274
<Content Include="SamplePages\Graph\PersonView.png" />
275275
<Content Include="SamplePages\Primitives\ConstrainedBox.png" />
276276
<Content Include="SamplePages\Primitives\SwitchPresenter.png" />
277+
<Content Include="SamplePages\RichSuggestBox\RichSuggestBox.png" />
277278
<Content Include="SamplePages\TabbedCommandBar\TabbedCommandBar.png" />
278279
<Content Include="SamplePages\Animations\Effects\FadeBehavior.png" />
279280
<Content Include="SamplePages\ColorPicker\ColorPicker.png" />
@@ -510,6 +511,10 @@
510511
<Compile Include="SamplePages\Shadows\AttachedDropShadowPage.xaml.cs">
511512
<DependentUpon>AttachedDropShadowPage.xaml</DependentUpon>
512513
</Compile>
514+
<Compile Include="SamplePages\RichSuggestBox\RichSuggestBoxPage.xaml.cs">
515+
<DependentUpon>RichSuggestBoxPage.xaml</DependentUpon>
516+
</Compile>
517+
<Compile Include="SamplePages\RichSuggestBox\SuggestionTemplateSelector.cs" />
513518
<Compile Include="SamplePages\TilesBrush\TilesBrushPage.xaml.cs">
514519
<DependentUpon>TilesBrushPage.xaml</DependentUpon>
515520
</Compile>
@@ -634,6 +639,7 @@
634639
<Content Include="SamplePages\Shadows\AttachedShadowCompositionXaml.bind" />
635640
<Content Include="SamplePages\Animations\Shadows\AnimatedCardShadowXaml.bind" />
636641
<Content Include="SamplePages\KeyDownTriggerBehavior\KeyDownTriggerBehaviorXaml.bind" />
642+
<Content Include="SamplePages\RichSuggestBox\RichSuggestBoxCode.bind" />
637643
</ItemGroup>
638644
<ItemGroup>
639645
<Compile Include="App.xaml.cs">
@@ -993,6 +999,14 @@
993999
<Generator>MSBuild:Compile</Generator>
9941000
<SubType>Designer</SubType>
9951001
</Page>
1002+
<Content Include="SamplePages\RichSuggestBox\RichSuggestBoxXaml.bind">
1003+
<SubType>Designer</SubType>
1004+
<Generator>MSBuild:Compile</Generator>
1005+
</Content>
1006+
<Page Include="SamplePages\RichSuggestBox\RichSuggestBoxPage.xaml">
1007+
<SubType>Designer</SubType>
1008+
<Generator>MSBuild:Compile</Generator>
1009+
</Page>
9961010
<Page Include="SamplePages\TilesBrush\TilesBrushPage.xaml">
9971011
<Generator>MSBuild:Compile</Generator>
9981012
<SubType>Designer</SubType>
@@ -1086,6 +1100,10 @@
10861100
<SubType>Designer</SubType>
10871101
<Generator>MSBuild:Compile</Generator>
10881102
</Content>
1103+
<Content Include="SamplePages\Triggers\ControlSizeTrigger.bind">
1104+
<SubType>Designer</SubType>
1105+
<Generator>MSBuild:Compile</Generator>
1106+
</Content>
10891107
<Page Include="SamplePages\Triggers\FullScreenModeStateTriggerPage.xaml">
10901108
<Generator>MSBuild:Compile</Generator>
10911109
<SubType>Designer</SubType>
34.7 KB
Loading
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
private void SuggestingBox_OnTokenPointerOver(RichSuggestBox sender, RichSuggestTokenPointerOverEventArgs args)
2+
{
3+
var flyout = (Flyout)FlyoutBase.GetAttachedFlyout(sender);
4+
var pointerPosition = args.CurrentPoint.Position;
5+
6+
if (flyout?.Content is ContentPresenter cp && sender.TextDocument.Selection.Type != SelectionType.Normal &&
7+
(!flyout.IsOpen || cp.Content != args.Token.Item))
8+
{
9+
this._dispatcherQueue.TryEnqueue(() =>
10+
{
11+
cp.Content = args.Token.Item;
12+
flyout.ShowAt(sender, new FlyoutShowOptions
13+
{
14+
Position = pointerPosition,
15+
ExclusionRect = sender.GetRectFromRange(args.Range),
16+
ShowMode = FlyoutShowMode.TransientWithDismissOnPointerMoveAway,
17+
});
18+
});
19+
}
20+
}
21+
22+
private void SuggestingBox_OnSuggestionChosen(RichSuggestBox sender, SuggestionChosenEventArgs args)
23+
{
24+
if (args.Prefix == "#")
25+
{
26+
args.Format.BackgroundColor = Colors.DarkOrange;
27+
args.Format.ForegroundColor = Colors.OrangeRed;
28+
args.Format.Bold = FormatEffect.On;
29+
args.Format.Italic = FormatEffect.On;
30+
args.DisplayText = ((SampleDataType)args.SelectedItem).Text;
31+
}
32+
else
33+
{
34+
args.DisplayText = ((SampleEmailDataType)args.SelectedItem).DisplayName;
35+
}
36+
}
37+
38+
private void SuggestingBox_OnSuggestionRequested(RichSuggestBox sender, SuggestionRequestedEventArgs args)
39+
{
40+
if (args.Prefix == "#")
41+
{
42+
sender.ItemsSource =
43+
this._samples.Where(x => x.Text.Contains(args.QueryText, StringComparison.OrdinalIgnoreCase));
44+
}
45+
else
46+
{
47+
sender.ItemsSource =
48+
this._emailSamples.Where(x => x.DisplayName.Contains(args.QueryText, StringComparison.OrdinalIgnoreCase));
49+
}
50+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.RichSuggestBoxPage"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
<Page.Resources>
10+
<ResourceDictionary>
11+
<local:SuggestionTemplateSelector x:Key="SuggestionTemplateSelector" />
12+
<local:NameToColorConverter x:Key="NameToColorConverter" />
13+
</ResourceDictionary>
14+
</Page.Resources>
15+
16+
<Grid Visibility="Collapsed">
17+
<controls:RichSuggestBox />
18+
<ListView />
19+
</Grid>
20+
</Page>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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 System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using Microsoft.Toolkit.Uwp.UI;
9+
using Microsoft.Toolkit.Uwp.UI.Controls;
10+
using Windows.System;
11+
using Windows.UI;
12+
using Windows.UI.Text;
13+
using Windows.UI.Xaml;
14+
using Windows.UI.Xaml.Controls;
15+
using Windows.UI.Xaml.Controls.Primitives;
16+
17+
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
18+
{
19+
/// <summary>
20+
/// An empty page that can be used on its own or navigated to within a Frame.
21+
/// </summary>
22+
public sealed partial class RichSuggestBoxPage : Page, IXamlRenderListener
23+
{
24+
private readonly List<SampleEmailDataType> _emailSamples = new List<SampleEmailDataType>()
25+
{
26+
new SampleEmailDataType() { FirstName = "Marcus", FamilyName = "Perryman" },
27+
new SampleEmailDataType() { FirstName = "Michael", FamilyName = "Hawker" },
28+
new SampleEmailDataType() { FirstName = "Matt", FamilyName = "Lacey" },
29+
new SampleEmailDataType() { FirstName = "Alexandre", FamilyName = "Chohfi" },
30+
new SampleEmailDataType() { FirstName = "Filip", FamilyName = "Wallberg" },
31+
new SampleEmailDataType() { FirstName = "Shane", FamilyName = "Weaver" },
32+
new SampleEmailDataType() { FirstName = "Vincent", FamilyName = "Gromfeld" },
33+
new SampleEmailDataType() { FirstName = "Sergio", FamilyName = "Pedri" },
34+
new SampleEmailDataType() { FirstName = "Alex", FamilyName = "Wilber" },
35+
new SampleEmailDataType() { FirstName = "Allan", FamilyName = "Deyoung" },
36+
new SampleEmailDataType() { FirstName = "Adele", FamilyName = "Vance" },
37+
new SampleEmailDataType() { FirstName = "Grady", FamilyName = "Archie" },
38+
new SampleEmailDataType() { FirstName = "Megan", FamilyName = "Bowen" },
39+
new SampleEmailDataType() { FirstName = "Ben", FamilyName = "Walters" },
40+
new SampleEmailDataType() { FirstName = "Debra", FamilyName = "Berger" },
41+
new SampleEmailDataType() { FirstName = "Emily", FamilyName = "Braun" },
42+
new SampleEmailDataType() { FirstName = "Christine", FamilyName = "Cline" },
43+
new SampleEmailDataType() { FirstName = "Enrico", FamilyName = "Catteneo" },
44+
new SampleEmailDataType() { FirstName = "Davit", FamilyName = "Badalyan" },
45+
new SampleEmailDataType() { FirstName = "Diego", FamilyName = "Siciliani" },
46+
new SampleEmailDataType() { FirstName = "Raul", FamilyName = "Razo" },
47+
new SampleEmailDataType() { FirstName = "Miriam", FamilyName = "Graham" },
48+
new SampleEmailDataType() { FirstName = "Lynne", FamilyName = "Robbins" },
49+
new SampleEmailDataType() { FirstName = "Lydia", FamilyName = "Holloway" },
50+
new SampleEmailDataType() { FirstName = "Nestor", FamilyName = "Wilke" },
51+
new SampleEmailDataType() { FirstName = "Patti", FamilyName = "Fernandez" },
52+
new SampleEmailDataType() { FirstName = "Pradeep", FamilyName = "Gupta" },
53+
new SampleEmailDataType() { FirstName = "Joni", FamilyName = "Sherman" },
54+
new SampleEmailDataType() { FirstName = "Isaiah", FamilyName = "Langer" },
55+
new SampleEmailDataType() { FirstName = "Irvin", FamilyName = "Sayers" },
56+
new SampleEmailDataType() { FirstName = "Tung", FamilyName = "Huynh" },
57+
};
58+
59+
private readonly List<SampleDataType> _samples = new List<SampleDataType>()
60+
{
61+
new SampleDataType() { Text = "Account", Icon = Symbol.Account },
62+
new SampleDataType() { Text = "Add Friend", Icon = Symbol.AddFriend },
63+
new SampleDataType() { Text = "Attach", Icon = Symbol.Attach },
64+
new SampleDataType() { Text = "Attach Camera", Icon = Symbol.AttachCamera },
65+
new SampleDataType() { Text = "Audio", Icon = Symbol.Audio },
66+
new SampleDataType() { Text = "Block Contact", Icon = Symbol.BlockContact },
67+
new SampleDataType() { Text = "Calculator", Icon = Symbol.Calculator },
68+
new SampleDataType() { Text = "Calendar", Icon = Symbol.Calendar },
69+
new SampleDataType() { Text = "Camera", Icon = Symbol.Camera },
70+
new SampleDataType() { Text = "Contact", Icon = Symbol.Contact },
71+
new SampleDataType() { Text = "Favorite", Icon = Symbol.Favorite },
72+
new SampleDataType() { Text = "Link", Icon = Symbol.Link },
73+
new SampleDataType() { Text = "Mail", Icon = Symbol.Mail },
74+
new SampleDataType() { Text = "Map", Icon = Symbol.Map },
75+
new SampleDataType() { Text = "Phone", Icon = Symbol.Phone },
76+
new SampleDataType() { Text = "Pin", Icon = Symbol.Pin },
77+
new SampleDataType() { Text = "Rotate", Icon = Symbol.Rotate },
78+
new SampleDataType() { Text = "Rotate Camera", Icon = Symbol.RotateCamera },
79+
new SampleDataType() { Text = "Send", Icon = Symbol.Send },
80+
new SampleDataType() { Text = "Tags", Icon = Symbol.Tag },
81+
new SampleDataType() { Text = "UnFavorite", Icon = Symbol.UnFavorite },
82+
new SampleDataType() { Text = "UnPin", Icon = Symbol.UnPin },
83+
new SampleDataType() { Text = "Zoom", Icon = Symbol.Zoom },
84+
new SampleDataType() { Text = "ZoomIn", Icon = Symbol.ZoomIn },
85+
new SampleDataType() { Text = "ZoomOut", Icon = Symbol.ZoomOut },
86+
};
87+
88+
private RichSuggestBox _rsb;
89+
private RichSuggestBox _tsb;
90+
private DispatcherQueue _dispatcherQueue;
91+
92+
public RichSuggestBoxPage()
93+
{
94+
this.InitializeComponent();
95+
this._dispatcherQueue = DispatcherQueue.GetForCurrentThread();
96+
Loaded += (sender, e) => { this.OnXamlRendered(this); };
97+
}
98+
99+
public void OnXamlRendered(FrameworkElement control)
100+
{
101+
if (this._rsb != null)
102+
{
103+
this._rsb.SuggestionChosen -= this.SuggestingBox_OnSuggestionChosen;
104+
this._rsb.SuggestionRequested -= this.SuggestingBox_OnSuggestionRequested;
105+
}
106+
107+
if (this._tsb != null)
108+
{
109+
this._tsb.SuggestionChosen -= this.SuggestingBox_OnSuggestionChosen;
110+
this._tsb.SuggestionRequested -= this.SuggestingBox_OnSuggestionRequested;
111+
this._tsb.TokenPointerOver -= this.SuggestingBox_OnTokenPointerOver;
112+
}
113+
114+
if (control.FindChild("SuggestingBox") is RichSuggestBox rsb)
115+
{
116+
this._rsb = rsb;
117+
this._rsb.SuggestionChosen += this.SuggestingBox_OnSuggestionChosen;
118+
this._rsb.SuggestionRequested += this.SuggestingBox_OnSuggestionRequested;
119+
}
120+
121+
if (control.FindChild("PlainTextSuggestingBox") is RichSuggestBox tsb)
122+
{
123+
this._tsb = tsb;
124+
this._tsb.SuggestionChosen += this.SuggestingBox_OnSuggestionChosen;
125+
this._tsb.SuggestionRequested += this.SuggestingBox_OnSuggestionRequested;
126+
this._tsb.TokenPointerOver += this.SuggestingBox_OnTokenPointerOver;
127+
}
128+
129+
if (control.FindChild("TokenListView1") is ListView tls1)
130+
{
131+
tls1.ItemsSource = this._rsb?.Tokens;
132+
}
133+
134+
if (control.FindChild("TokenListView2") is ListView tls2)
135+
{
136+
tls2.ItemsSource = this._tsb?.Tokens;
137+
}
138+
}
139+
140+
private void SuggestingBox_OnTokenPointerOver(RichSuggestBox sender, RichSuggestTokenPointerOverEventArgs args)
141+
{
142+
var flyout = (Flyout)FlyoutBase.GetAttachedFlyout(sender);
143+
var pointerPosition = args.CurrentPoint.Position;
144+
145+
if (flyout?.Content is ContentPresenter cp && sender.TextDocument.Selection.Type != SelectionType.Normal &&
146+
(!flyout.IsOpen || cp.Content != args.Token.Item))
147+
{
148+
this._dispatcherQueue.TryEnqueue(() =>
149+
{
150+
cp.Content = args.Token.Item;
151+
flyout.ShowAt(sender, new FlyoutShowOptions
152+
{
153+
Position = pointerPosition,
154+
ExclusionRect = sender.GetRectFromRange(args.Range),
155+
ShowMode = FlyoutShowMode.TransientWithDismissOnPointerMoveAway,
156+
});
157+
});
158+
}
159+
}
160+
161+
private void SuggestingBox_OnSuggestionChosen(RichSuggestBox sender, SuggestionChosenEventArgs args)
162+
{
163+
if (args.Prefix == "#")
164+
{
165+
args.Format.BackgroundColor = Colors.DarkOrange;
166+
args.Format.ForegroundColor = Colors.OrangeRed;
167+
args.Format.Bold = FormatEffect.On;
168+
args.Format.Italic = FormatEffect.On;
169+
args.DisplayText = ((SampleDataType)args.SelectedItem).Text;
170+
}
171+
else
172+
{
173+
args.DisplayText = ((SampleEmailDataType)args.SelectedItem).DisplayName;
174+
}
175+
}
176+
177+
private void SuggestingBox_OnSuggestionRequested(RichSuggestBox sender, SuggestionRequestedEventArgs args)
178+
{
179+
if (args.Prefix == "#")
180+
{
181+
sender.ItemsSource =
182+
this._samples.Where(x => x.Text.Contains(args.QueryText, StringComparison.OrdinalIgnoreCase));
183+
}
184+
else
185+
{
186+
sender.ItemsSource =
187+
this._emailSamples.Where(x => x.DisplayName.Contains(args.QueryText, StringComparison.OrdinalIgnoreCase));
188+
}
189+
}
190+
}
191+
}

0 commit comments

Comments
 (0)